Continuous Fire Animations

Explanation of how to make a gun use a continuous firing animation rather than a stop/start one.

By default, the shoot animation of a gun will return to its idle frame when it is finished, even if the fire button is held down. However, this isn't always what is desired, particularly with certain automatic weapons where returning to the idle frame looks awkward.

This is where Continuous Firing Animations come in. Guns with continuous firing animations will loop the specified section of their animation while firing, and return to the first frame of their fire animation upon the fire button being released. (this is also useful for guns that may have some sort of warmup animation when they start to fire, such as a gatling gun whose barrel spins slow at first but gets faster).

How to make a gun use a Continuous Fire Animation

  1. Set up the gun's sprites and animation the way you would normally do it to begin with.

  2. Make sure the bool 'usesContinuousFireAnimation' is set to true, like this;

gun.usesContinuousFireAnimation = true;

3. Now you need to set up a looped section in the gun's firing animation, which you can do by using the code below.

gun.GetComponent<tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).wrapMode = tk2dSpriteAnimationClip.WrapMode.LoopSection;
gun.GetComponent<tk2dSpriteAnimator>().GetClipByName(gun.shootAnimation).loopStart = 1;

Please note that the 'loopStart' variable is the frame on which the gun's animation will begin to loop. In this example, it is set to 1, but since computers count starting at 0, '1' actually refers to the second frame of the animation. For a loop to start on the first frame, 'loopStart' would have to be set to 0.

Other Notes

It is worth mentioning that upon the fire button being released, the gun will return to the first frame of its fire animation, not its idle one. To get around this, it may be advisable to set the first frame of the fire animation to the idle frame and start the loop on the second frame.

This way, the gun will still have a continuous looping firing animation, but will not persist on it's firing animation once firing has ended (or so it will appear to any end-user).

Last updated