Hello there. This will be my first time using this site to seek assistance, so apologies if I do anything incorrectly. I am a newer developer and have been training myself for a few weeks now. My dilemma is this:
I am attempting to animate a sprite. This is simple enough. I have created a Sprite2D on the Character2D node as a child, and I have loaded the .png of the [idle] sprite sheet as a texture. I have hen used the animation window at the bottom to set the key frames, etc. The animation functions as expected.
I then created some collision bodies for detecting when the character is struck (the game is basically “don’t let your avatar get touched by the mobs” like in the Godot “Dodge the Creeps” tutorial). I used one for the body (it’s a deer) as a rectangle, and one for the head. I did this because the idle animation has the deer’s head turn, and so the collision area changes based on the animations current frame. The body collision shape is a rectangle and needs to be adjusted when the sprite changes from left to right facing.
All of this I have successfully done (I think…haven’t actually had a chance to use the animation but it is set up now). But the sprite I am using has multiple files for its sprite assets. It has separate .png files for walk, take damage, die, and idle. I have set it up for the idle animation and used key frames to adjust collision bodies as needed, but I do not understand how to set up the other animations using the other .png files so that it uses the texture from the appropriate .png based on conditions.
I have attempted to resolve this problem by using the AnimatedSprite2D instead, but that route results in not knowing how to set up key frames to mark changes in the positioning of the collision bodies. One way has one issue and the other another.
I’m writing here in the hopes that this is some sort of “noob” issue that I just haven’t learned yet and will be easily revealed. I have used the scale settings to adjust collision areas before but recently learned that this can cause issues later on due to how that works in the physics engine (as explained at 3:54 here https://youtu.be/zLdTvkLsmgA?si=Tkx9TikJsvbGrpEi&t=234 ). So this whole “key frames to move collision boxes” was a solution to avoid that potential danger entirely.
If anyone can assist with pointing me in the right direction to either add the key frames to the AnimatedSprite2D, or add additional sprite sheets to the Sprite2D, or knows another method to accomplish these goals that I can research further to use instead…I would very much appreciate your knowledge.
You can keyframe any property in an AnimationPlayer. This includes the Sprite2D.texture property. So, on each animation you can keyframe the spritesheet where the frames for that animation are.
To keyframe a sprite sheet they seem to need to be attached to the Sprite2D (do they not?), and I havent been able to figure out how to add a second sprite sheet to the sprite2d. once Ive added one it seems to only allow it to have that single one.
In the grand scheme of things I could try to take the separate sheets and make them into a single pdf, but that would be a considerable amount of doing for someone like myself with next to know artistic skill, and it would have to be done for the separate shadows sprite sheets that go under the characters.
Another option the internet seems to suggest has been having multiple Sprite2Ds for each sprite sheet and then coding in show() and hide() for all the different Sprite2Ds so only one shows at a time depending on the animation. I have managed to get this to work but the amount of “code” needed for this, and the complexity of adding new animations down the road (as it grows it will get very messy, or at least it seems like it will from what i see and how I did it).
Im really looking for a “friendly” method to implement multiple animations using multiple sheets without the code or the scene tree having to become clogged with a bunch of duplicates. Perhaps there isnt a way, but surely this sort of thing has been common enough that Im not the first to experience this.
Does any of this fit with what you are trying to explain to me, or is there another way Im missing that your trying to point out?
You can change it and keyframe the new texture. You’ll need to do it in every animation. If you have idle, walk and run spritesheets then your for your idle animation you’d need to set the idle spritesheet as the Sprite2D.texture, keyframe it in the first frame of the animation, and keyframe the frames of the animation. Do the same with your other animations and spritesheets.
Just seeing this now and that would’ve been a good idea had I seen it sooner. I did end up finding a solution through another route. I used an AnimatedSprite2D instead of a Sprite2D for the base, and then used the “frames from sprite sheet” for each animation to pull in the correct frames from the correct sprite sheet.
Its nice to have knowledge of TWO methods tho for the future, so thank you very much friend
Ill mark this with a link to your reply so that anyone arriving here in future can see both options as the marked solution. Thank you so much. <3