- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Animation
        nhmkdev edited this page Feb 5, 2014 
        ·
        2 revisions
      
    The Animation system is used to spawn entities that play animations and interact with existing entities.
This system is completely experimental / Work in progress -- just intended to investigate how one might approach the subject.
An Animation is the following:
- A non-visible controller entity
- A set of one or more animated entities that are spawned
- An infrastructure for making calls to and adjusting entities.
var Animations = ig.global.data.anims;
var Anim = ig.support.anim;
Notes:
- The animation object format itself is consistent with the Animation Object with an additional field for firing events on a given frame of animation called actseq.
Animations.sparkle =
{
    s: // settings
    {
        fa:true, // flipped allowed (meaning the offset entity can meet the requirements on the left/right)
        dc:true // disable player controls (no input)
    },
    es: // entity specific settings
    [
        // NOTE: the first entity is the static entity around which the others must move
        {
            n:'_initiator', // name of the entity '_initiator' is a special indicator of the entity that started the animation
        },
        {
            n:'player',
            x:6, // xoffset from the static entity (default: 0)
            y:0, // yoffset from the static entity (default: 0)
        },
    ],
    ao: // animation object
    {
        i:'sparkle', // image name ('media/' is prepended)
        w:8, // width of frame
        h:8, // height of frame
        a: // array of animation states (should only have 1)
        [
            {
                n:'swing', // name is non-critical in current implementation
                ft:0.1, // frametime
                seq:[0, 0, 0, 0, 1, 2, 0, 1, 2, 3], // sequence
                actseq:
                [
                    { f:8, e:'player', k:'ps' } // on frame 8 (or higher if skipped, execute the animAction on the player
                ],
                s:true
            }
        ]
    }
}
The action sequence field is used to specify a frame on which to call animAction on the associated entity. The prototype for the method is animAction(key, val) and both inputs are optional depending on the needs of the situation. The array of actions should be in ascending order of f values (I could build in sorting but for now... no).
actseq:
    [
        { 
            f:8, // frame to act on 
            e:'player', // entity to call function of (may be '_initiator')
            k:'ps', // key to pass to the function (not required)
            v:null // value to pass to the function (not required)
        }
    ],
Below is an example from Dialog.
ig.game.spawnEntity( EntitySupportAnim, entity.pos.x, entity.pos.y, {animId:animId, entity:entity} );