Trying to make my first game. Got stuck

So basically i have a problem where i can’t really get sprites to change when a certain criteria is met.
I’m using a godot v4.2.1.
Any idea why things don’t work?
Thanks for help

I may be a total idiot and use wrong function because programming is something completely new to me

Getting a look at the rest of your script might help us figure out what exactly the problem is here, but I’m guessing it probably has to do with the function you’re calling; _on_sprite_2d_texture_changed() is only called after the texture of the Sprite2D node changes, so if you’re only trying to change the texture within that function, it won’t do anything. Conversely, if the texture of the Sprite2D node ever DOES change, it will call this function, which will change the texture again, which will call the function again and result in a loop where your sprite is set to “3 sk.png” every game frame as long as fullness is equal to stuffed.

I’d also like to take this opportunity to point out that Godot’s Sprite2D node supports sprite sheets, so there shouldn’t be many cases where you have to swap the actual texture like this. You can just have all your sprites for a character in one big sheet which you set as the texture file, and then use code to change which part of the spritesheet is shown on your Sprite2D.

1 Like


Well there is not much and i got stuck pretty early on and i think i’ll try to make it into a spritesheet and try it that way

Yeah, this confirms that the function you’re using is the issue, since the only part of your code that changes the sprite is in a function that can only be called once the sprite is changed. If you moved the code that is under _on_sprite_2d_texture_changed() to be under _on_texture_button_2_pressed() it would probably work.

I’m not exactly an expert programmer myself, but if you want you can add me at _scoffles on Discord and I might be able to give you some pointers if you need help with anything else.

1 Like

Dude! It works! Right now you’re a magician in my eyes!