Commander Wars Battleanimation System - Robosturm/Commander_Wars GitHub Wiki
Battleanimation Sequence
Battleanimations will be executed in the following order:
- move in Animation (can be skipped) default for all units at the moment
- callback: loadMoveInAnimation : function(sprite, unit, defender, weapon)
- enable: hasMoveInAnimation return true if the unit can move in before fire
- duration: getMoveInDurationMS duration of the move in animation in ms
- standing Animation
- callback: loadStandingAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: none
- Attacker Fire Animation
- callback: loadFireAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: getFireDurationMS duration of the fire animation in ms
- load Attacker standing fired Animation
- callback: loadStandingFiredAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: none
- Attacker Impact Animation -> shows the impact on the enemy
- callback: loadImpactAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: getImpactDurationMSduration of the fire animation in ms
- Defender Fire Animation
- callback: loadFireAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: getFireDurationMS duration of the fire animation in ms
- load Defender standing fired Animation
- callback: loadStandingFiredAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: none
- Defender Impact Animation
- callback: loadImpactAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: getImpactDurationMSduration of the fire animation in ms
- wait
- callback: loadStandingFiredAnimation: function(sprite, unit, defender, weapon)
- enable: always on
- duration: none
- Battleanimation end
Other callbacks:
- getPositionOffset : function(sprite, unit, terrain, unitIdx)
- Called for every loaded sprite should return terrain specific offests for certain unit models
- getMaxUnitCount : function()
- returns the maximum amount of unit models in AW mosttimes this is 5 or 1
Functions provided to load sprites
The "sprite" object of the callbacks provides the following functions for loading some sprites (images). For model based sprites:
/**
* @brief loadSprite loads a standing animated sprite for every shown model
* @param spriteID the sprite resource which should be loaded
* @param addPlayerColor apply the player color to this sprite or not
* @param maxUnitCount maximum unit count. Needed to create the amount of models of this sprite based on the units hp
* @param offset offset from the original model position
* @param loop the amount of loops played for an animated sprite
* @param scale scale of the sprite 1.0 -> no scaling
* @param priority priority order in which this sprite will be shown
* @param showDelay delay before showing this sprite
* @param invertFlipX if true the flipping of the sprite is inverted needed for impacts of rockets etc.
* @param deleteAfter deletes the sprite after finished movement or animation
*/
void loadSprite(QString spriteID, bool addPlayerColor, qint32 maxUnitCount, QPoint offset,
qint32 loop = 1, float scale = 1.0f, short priority = 0, qint32 showDelay = 0,
bool invertFlipX = false, bool deleteAfter = false);
For moving model based sprites:
/**
* @brief loadMovingSprite loads a moving sprite for every shown model
* @param spriteID the sprite resource which should be loaded
* @param addPlayerColor apply the player color to this sprite or not
* @param maxUnitCount maximum unit count. Needed to create the amount of models of this sprite based on the units hp
* @param offset offset from the original model position
* @param movement movement of the animation as point
* @param moveTime time to reach the target
* @param deleteAfter deletes the sprite after finished movement or animation
* @param loop the amount of loops played for an animated sprite
* @param scale scale of the sprite 1.0 -> no scaling
* @param priority priority order in which this sprite will be shown
* @param showDelay delay before showing this sprite
* @param invertFlipX if true the flipping of the sprite is inverted needed for impacts of rockets etc.
*/
void loadMovingSprite(QString spriteID, bool addPlayerColor, qint32 maxUnitCount, QPoint offset,
QPoint movement, qint32 moveTime, bool deleteAfter = false,
qint32 loop = 1, float scale = 1.0f, short priority = 0, qint32 showDelay = 0,
bool invertFlipX = false);
For a custom single placed sprites:
/**
* @brief loadSingleMovingSprite loads a single sprite for a unit
* @param spriteID the sprite resource which should be loaded
* @param addPlayerColor apply the player color to this sprite or not
* @param maxUnitCount maximum unit count. Needed to create the amount of models of this sprite based on the units hp
* @param offset offset from the original model position
* @param movement movement of the animation as point
* @param moveTime time to reach the target
* @param deleteAfter deletes the sprite after finished movement or animation
* @param loop the amount of loops played for an animated sprite
* @param scale scale of the sprite 1.0 -> no scaling
* @param priority priority order in which this sprite will be shown
* @param showDelay delay before showing this sprite
* @param invertFlipX if true the flipping of the sprite is inverted needed for impacts of rockets etc.
*/
void loadSingleMovingSprite(QString spriteID, bool addPlayerColor, QPoint offset,
QPoint movement, qint32 moveTime, bool deleteAfter = false,
qint32 loop = 1, float scale = 1.0f, short priority = 0, qint32 showDelay = 0,
bool invertFlipX = false);
Function provided to play background sound
The "sprite" object of the callbacks provides the following functions for loading some sounds during the play of the animation.
/**
* @brief loadSound
* @param file sound file
* @param loops amount of loops for this file -2 for while this animation is shown
* @param folder resource folder of the sound
* @param delay before this sound is played after this function was called
*/
void loadSound(QString file, qint32 loops, QString folder = "resources/sounds/", qint32 delay = 0);
Battleanimation Coordinate System and how to find the required positions for sprites.
The main thing to remember is that the coordinates point (0/0) is in the lower left corner of the battleanimation screen. This is contrary to tools like paint, gimp etc. where the coordinates point (0/0) is in the upper left corner.
How to find the correct position of an fire animation like the mg-fire.
- Determine the general offset position of one model e.g. ModelPos(-20, 5)
- Determine the position of the machine gun in the model using a drawing tool from the lower left corner. e.g. MgPos(40, 20)
- Determine the position of the mg fire position using a drawing tool from the lower left corner e.g. MgFirePos(0, 5)
- Calculate the X-Coordinate which is ModelPos.X + MgPos.X - MgFirePos.X
- Calculate the Y-Coordinate which is ModelPos.Y + MgPos.Y - MgFirepos.Y