Godot Version
4.4.1 Stable
Question
Hi, I’m pretty new to GODOT (less than a week :))
So i’ve written a small game that changes the background as progress through every level.
I’m on MacOS and it works fine every time during testing in dev in the editor.
I load and update my back ground on startup
# Load background sprite (assumed path)
bg_sprite = get_node("Background")
# Existing setup
GameState.level_changed.connect(_on_level_changed)
update_background_for_level(GameState.level)
Background is a Spriet2D
Bg folder is a child of res:// and contains jpg files 1 to 30.jpg
I update like this as the level goes higher:
func update_background_for_level(level: int):
var bg_path = “res://Bg/%d.jpg” % clamp(level, 1, 30)
var image_texture = ImageTexture.new()
var image = Image.load_from_file(bg_path)
if image != null:
image_texture.set_image(image)
var bg_sprite = get_node("Background")
bg_sprite.texture = image_texture
bg_image = image # update for spawn logic
else:
print("Failed to load background for level: ", level)
Again this all works fine in dev but when I export to Web (Runnable) the game still kinda works but the background won’t update.
Looking in the javascript console i’m getting this error:
OpenGL API OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium)) - Compatibility - Using Device: WebKit - WebKit WebGL
index.js:459 [GameState:<Node#23655875792>, MainScene:<Node2D#28705817811>]
index.js:474 ERROR: Error opening file ‘res://Bg/1.jpg’.
onPrintError @ index.js:474
put_char @ index.js:9
write @ index.js:9
write @ index.js:9
doWritev @ index.js:9
_fd_write @ index.js:9
$func65592 @ 0a6b2fda:0x25bf877
$func65715 @ 0a6b2fda:0x25c6529
$func65722 @ 0a6b2fda:0x25c71fd
$func53904 @ 0a6b2fda:0x2168b38
$func53902 @ 0a6b2fda:0x21688d8
$func53901 @ 0a6b2fda:0x2168878
$func53906 @ 0a6b2fda:0x2168cac
$func62846 @ 0a6b2fda:0x248365f
$func62848 @ 0a6b2fda:0x24837a0
$func53795 @ 0a6b2fda:0x214f026
$func53637 @ 0a6b2fda:0x213fc6f
$func12041 @ 0a6b2fda:0xac5848
$func5616 @ 0a6b2fda:0x626471
$func5468 @ 0a6b2fda:0x61833a
$func62092 @ 0a6b2fda:0x241c1dd
$func55355 @ 0a6b2fda:0x223ac90
$func5616 @ 0a6b2fda:0x62604f
$func5468 @ 0a6b2fda:0x61833a
$func17100 @ 0a6b2fda:0x12580ac
$func16382 @ 0a6b2fda:0x1225e94
$func62070 @ 0a6b2fda:0x24191e4
$func17129 @ 0a6b2fda:0x1259fd0
$func17129 @ 0a6b2fda:0x1259f83
$func17126 @ 0a6b2fda:0x1259e58
$func17470 @ 0a6b2fda:0x1274a22
$_Z14godot_web_mainiPPc @ 0a6b2fda:0xd278b
$__main_argc_argv @ 0a6b2fda:0xd6be5
(anonymous) @ index.js:9
callMain @ index.js:9
(anonymous) @ index.js:801
(anonymous) @ index.js:796
Promise.then
start @ index.js:775
(anonymous) @ index.js:834
Promise.then
startGame @ index.js:833
(anonymous) @ index.html:203
(anonymous) @ index.html:217Understand this error
index.js:474 at: load_image (core/io/image_loader.cpp:89)
onPrintError @ index.js:474
put_char @ index.js:9
write @ index.js:9
write @ index.js:9
doWritev @ index.js:9
_fd_write @ index.js:9
$func65592 @ 0a6b2fda:0x25bf877
$func65715 @ 0a6b2fda:0x25c6529
$func65722 @ 0a6b2fda:0x25c71fd
$func53904 @ 0a6b2fda:0x2168b38
$func53902 @ 0a6b2fda:0x21688d8
$func53901 @ 0a6b2fda:0x216889a
$func53906 @ 0a6b2fda:0x2168cac
$func62846 @ 0a6b2fda:0x248365f
$func62848 @ 0a6b2fda:0x24837a0
$func53795 @ 0a6b2fda:0x214f026
$func53637 @ 0a6b2fda:0x213fc6f
$func12041 @ 0a6b2fda:0xac5848
$func5616 @ 0a6b2fda:0x626471
$func5468 @ 0a6b2fda:0x61833a
$func62092 @ 0a6b2fda:0x241c1dd
$func55355 @ 0a6b2fda:0x223ac90
$func5616 @ 0a6b2fda:0x62604f
$func5468 @ 0a6b2fda:0x61833a
$func17100 @ 0a6b2fda:0x12580ac
$func16382 @ 0a6b2fda:0x1225e94
$func62070 @ 0a6b2fda:0x24191e4
$func17129 @ 0a6b2fda:0x1259fd0
$func17129 @ 0a6b2fda:0x1259f83
$func17126 @ 0a6b2fda:0x1259e58
$func17470 @ 0a6b2fda:0x1274a22
$_Z14godot_web_mainiPPc @ 0a6b2fda:0xd278b
$__main_argc_argv @ 0a6b2fda:0xd6be5
(anonymous) @ index.js:9
callMain @ index.js:9
(anonymous) @ index.js:801
(anonymous) @ index.js:796
Promise.then
start @ index.js:775
(anonymous) @ index.js:834
Promise.then
startGame @ index.js:833
(anonymous) @ index.html:203
(anonymous) @ index.html:217Understand this error
index.js:474 ERROR: Failed to load image. Error 7
onPrintError @ index.js:474
put_char @ index.js:9
write @ index.js:9
write @ index.js:9
doWritev @ index.js:9
_fd_write @ index.js:9
$func65592 @ 0a6b2fda:0x25bf877
$func65715 @ 0a6b2fda:0x25c6529
$func65722 @ 0a6b2fda:0x25c71fd
$func53904 @ 0a6b2fda:0x2168b38
$func53902 @ 0a6b2fda:0x21688d8
$func53901 @ 0a6b2fda:0x2168878
$func53906 @ 0a6b2fda:0x2168cac
$func62846 @ 0a6b2fda:0x248365f
$func62848 @ 0a6b2fda:0x24837a0
$func53637 @ 0a6b2fda:0x213fccd
$func12041 @ 0a6b2fda:0xac5848
$func5616 @ 0a6b2fda:0x626471
$func5468 @ 0a6b2fda:0x61833a
$func62092 @ 0a6b2fda:0x241c1dd
$func55355 @ 0a6b2fda:0x223ac90
$func5616 @ 0a6b2fda:0x62604f
$func5468 @ 0a6b2fda:0x61833a
$func17100 @ 0a6b2fda:0x12580ac
$func16382 @ 0a6b2fda:0x1225e94
$func62070 @ 0a6b2fda:0x24191e4
$func17129 @ 0a6b2fda:0x1259fd0
$func17129 @ 0a6b2fda:0x1259f83
$func17126 @ 0a6b2fda:0x1259e58
$func17470 @ 0a6b2fda:0x1274a22
$_Z14godot_web_mainiPPc @ 0a6b2fda:0xd278b
$__main_argc_argv @ 0a6b2fda:0xd6be5
(anonymous) @ index.js:9
callMain @ index.js:9
(anonymous) @ index.js:801
(anonymous) @ index.js:796
Promise.then
start @ index.js:775
(anonymous) @ index.js:834
Promise.then
startGame @ index.js:833
(anonymous) @ index.html:203
(anonymous) @ index.html:217Understand this error
index.js:474 at: load_from_file (core/io/image.cpp:2554)