Topic was automatically imported from the old Question2Answer platform.
Asked By
mj4life92
Hi, I am following some tutorials on youtube on how to create multiple animations using AnimationPlayer node. In the tutorial (https://www.youtube.com/watch?v=ATfE4k6EP9U&ab_channel=TheDevDoc) they made 2 animations. I tried the same thing, but the problem I am facing is that the 2nd animation will override the first one. So basically in both my “walk” and “attack” animations, my enemy will attack.
Here is what I have in my enemy scene:
Sprite
CollisionShape2d
AnimationPlayer
Here are my steps:
Click on the ‘Animation’ button and hit ‘NEW’
I will name this ‘walk’ and hit ‘ok’
In my tree, I click on the Sprite → then I drag and drop my ‘walk.png’ file containing 8 frames of animation into the Sprite Texture
In the AnimationPlayer, I click on ‘Add Track’ → Property Track → “Pick the node that will be animated” , here I chose Sprite → then select the ‘frame’ property
I click on the Sprite again and under the ‘Animation’ property I select the Hframes (in my case 8 since there are 8 frames of animation in my png) → then I select Frame to be 0 → then I click on the key next to it 8 times to add all frames
I play the selected animation (the only one at the moment) and everything looks okay and I save
I then repeat from step 1), I create a new animation, go on the sprite again and add another one called “attack.png” which I add to my sprite and then add the keys.
After this is done I know have 2 animations, 1 for walk and 1 for attack, but when I switch between them in AnimationPlayer by using the dropdown arrow, both of the animations will have the key frames set from the latest steps performed ( from attack). Now both walk and attack have the attack keyframes set…
I don’t get what I’m doing wrong…i just want to use multiple animations. I am also a newb btw…
This 6 minute video give the complete answer to your question, please spread this around for others having the same problem.
thanks! I really thought it would solve this issue, but I followed this video and the animations are still being overriden by the frames used in the last sprite texture.
Does this have anything to do with the fact that the number of horizontal frames varies between animations? For ‘walk’ I use 8 frames but for ‘attack’ there are 5 frames. I do change these in the Sprite Animation properties for each animation I create using AnimationPlayer. Should I try adding Hframes as a track in the AnimationPlayer?
mj4life92 | 2022-12-16 16:00
I just followed the video guide bit by bit and made sure I got everything correctly and it worked for me.
Try deleting everything from the player node and start over. Make sure the V frames and H Frames are correct. You’ll know they are correct if you only see one frame per frame click. Then follow the guide
DarthPlayer | 2022-12-16 16:13
Based on the video I think I narrowed this down a bit more, here is what we have so far:
I tried this using 2 animations which have the exact same number of frames, 5.
AnimationPlayer → Animation → New → created a new animation called ‘dead’
Sprite → drag and drop the “Dead.png” into “Texture” field
Click on the little key next to “Texture” field to add to the AnimationPlayer track , clicked on Create
HFrames → 5
Added HFrames to track by using the key (I tried with and without this)
Frame → 0
Clicked on the little key next to Frame which created the ‘frame’ property in AnimationPlayer
Frame 0 was added at 0, I manually clicked on 0.1 on the track time scale
In the Sprite, clicked the little key to add Frame 1
Added Frame 2, 3, 4
Changed animation length to 0.5
Saved
2nd Animation
Clicked on Animation button in AnimationPlayer
14, New → created “attack” animation
Clicked on Sprite
Drag and drop the “attack.png” to the Sprite Texture field and saved
At this point even, if I switch from “attack” to “dead” animation in the AnimationPlayer, both the attack and dead animations will have the dead animation frames instead of being different…
mj4life92 | 2022-12-16 16:28
thanks for your help! It turns out I was very very high and was doing things in a different order. It works now that I am sober.