Setting Sprite2D texture proprerty

Godot Version

Godot 4.3

Question

how to set new frame in a Sprite2D item???

I defined Sprite2D item and set Texture proprierty by setting a png image; but if after I wanna change texture by drag&drop a new image It is not possible… :confused:

A new frame? Are you animating or just want to change the texture?

I mean, I want to chande texture (it is like a tilesheet) such that I can have more frames sll within the same animation

You can change the texture property in code. If you want to do animation frames, though, AnimatedSprite2D will do that with a single sprite sheet texture and less hoop-jumping.

With AnimatedSprite2D, you can set the animation frames, and if you turn autoplay off you can manually set frames to pick what it’s currently displaying. Or you can make multiple animations that use one or more of the frames in the spritesheet and switch which animation is playing.

My advice would be to use AnimatedSprite2D unless you have a good reason not to. Is there something you’re trying to do that’s a bad fit for it?

oh, the fact is that I cannot understand how to recover what It was working on…I am using AnimationPlayer and a Sprite2D.

Could you post your code?

ok, at now I am using a Sprite2D item and define animation I am interested to like for example:
-Idle
-walking

for each animation I add track about:
texture
hframes
vframes
frame
i set as value for the texture proprierty a png file which contains the frames for the appropriate animation.
I finding problems when I move from an animation to another one because It get always the previous png file…

You probably want to put all your animations in a single texture if you can, even if that makes the texture fairly large. Is there a reason you can’t or don’t want to?

Honestly in my plan I wanted to separate animation in own file… It looks to me more well organized..do you agree??

In the abstract it might make the files on disk more organized, but it’s forcing you to do extra work at runtime to support it. If you stitch the files together it’s something you do once at build time. If you keep them separate, you’re jumping hoops every time you switch animations, and you’re opening the door to new and interesting bugs in the code supporting it.

You do you, obviously, but part of my philosophy in game dev is:

  • don’t do at runtime what you can do at load; even if it takes longer, it happens once and not during gameplay
  • don’t do at load what you can do during the build; if it’s not running on the player’s machine it can’t cause problems for them
  • don’t do during the build what you can do once; the cheapest code to write and maintain is “none”

So, under these circumstances, personally I’d have the animations merged into per-type-of-object textures at least, so I wasn’t having to switch textures at runtime. If the animations were changing a lot during development I might consider keeping them separate until build time and making a tool to stitch them together, but otherwise I’d hand-bake them when they changed.

It can be very easy to fall into the trap of overengineering a project like this, but the player (who we’re building this for, ultimately) isn’t going to see your asset file layout or anything else you’ve got under the hood, no matter how well organized it is. If the organization is helping you with development, that’s potentially useful, but it’s very easy to get lost in the weeds and burn a bunch of dev time polishing some internal component nobody will ever see to a high shine.

Ok, so I am going to merge all animations toghether in same png file. However I think then it is required using Region attribute to select the right frame. I guess so…

Have you looked at AnimatedSprite2D? It lets you define multiple animations…

mm, honestly I didn’t as I was going to use AnimationPlayer…