The screenshot above is the default stance of the flute animation. This stance is waiting for input from the player.
When implementing this animation I needed to create variables for the character, so I could tell the software what animation is being played, whether it should be reversed or not and to stop idle animation from being played:
I made three flute animation specific variables, so I can distinguish the flute animation introduction, whether the flute is being played and whether the first fame of the selected music note has been played.
To even get started on the animation, I needed a way to gather data from what note is being played, hence this:
With the data gathered, I made the introduction animation play:
The code above makes sure the right sprite animation is chosen, is playing and is at the right starting place. Once activated, it gets locked until requested again.
Following on from this, I made the animation stay static when it gets to an idle stance:
If I did this, so I can tell when the intro animation is over and I can wait for a request, but the first time it already has a request.
Afterwards I let the animation play fully and applied a sound, which I removed from the guard music cues.
Once the animation reaches it’s last frame, I reset the animation to the default stance, to wait for an input:
With this code, the animation was finished for all 3 music notes, but I needed to restrict other animation from playing, while the flute was being used and I needed away out of the cycle.
To start with I restricted all animation non-flute related by adding in a restriction, here’s an example:
There isn’t an animation in this screenshot, but it does affect animation speed when a player is running and standing still. I may need to add a different or more restrictions if I add any more animation in this, but currently it works fine.
After the restrictions were put in, i needed a way to exit the animation cycle, so I coded this:
The above code checks if the right or left movement keys are being pressed. If so it then checks what animation is being played. If a flute animation is being played, it checks to see if it has reached a certain point in the animation. If is has reached the required animation frame, it sets the image index and reverses the animation. After a timer is up, it stops animation from reversing.
I am proud with what I have achieved and shocked you read this far.
I was having some probably with the code and they were animation playing too long, animation not stopping and animation not playing. All these were due to me not putting in restrictions to stop other animation and me not considering that animation gets priority of code.
One thought on “Update: Hero Flute Animation In-Game and optimized”