Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser mixed animation

 preload ()
    {
        this.load.atlas('knight', 'assets/animations/knight.png', 'assets/animations/knight.json');
        this.load.image('bg', 'assets/skies/clouds.png');
        this.load.spritesheet('tiles', 'assets/tilemaps/tiles/fantasy-tiles.png', { frameWidth: 64, frameHeight: 64 });
    }

    create ()
    {
        //  The background and floor
        this.add.image(400, 48, 'bg').setOrigin(0.5, 0);

        for (var i = 0; i < 13; i++)
        {
            this.add.image(64 * i, 536, 'tiles', 1).setOrigin(0);
        }

        var text = this.add.text(400, 8, 'Click to play
Idle to Run mix: 1500ms
Run to Idle mix: 500ms', { color: '#ffffff', align: 'center' }).setOrigin(0.5, 0);

        //  Our animations

        this.anims.create({
            key: 'idle',
            frames: this.anims.generateFrameNames('knight', { prefix: 'idle/frame', start: 0, end: 5, zeroPad: 4 }),
            frameRate: 8,
            repeat: -1
        });

        this.anims.create({
            key: 'run',
            frames: this.anims.generateFrameNames('knight', { prefix: 'run/frame', start: 0, end: 7, zeroPad: 4 }),
            frameRate: 12,
            repeat: -1
        });

        //  Set a mix between 'idle' and 'run'.

        //  When transitioning from idle to run it will wait 1500ms before starting the run animation
        this.anims.addMix('idle', 'run', 1500);

        //  When transitioning from run to idle it will wait 500ms before starting the idle animation
        this.anims.addMix('run', 'idle', 500);

        var lancelot = this.add.sprite(500, 536)

        lancelot.setOrigin(0.5, 1);
        lancelot.setScale(8);
        lancelot.play('idle');

        this.input.on('pointerdown', function () {

            if (lancelot.anims.getName() === 'idle')
            {
                lancelot.play('run');
            }
            else if (lancelot.anims.getName() === 'run')
            {
                lancelot.play('idle');
            }

        });
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser animation on repeat event 
Javascript :: phaser pause animation instances 
Javascript :: phaser show animation play through js 
Javascript :: regular expression a-z and 0-9 
Javascript :: closre in js 
Javascript :: generate random email account javascript 
Javascript :: permissions in chrome extension javascript 
Javascript :: Opposites attract 
Javascript :: js undici fetch stream data 
Javascript :: reactjs moment to string 
Javascript :: hot reload nestjs 
Javascript :: call back filter 
Javascript :: golang read json file 
Javascript :: react native geolocation 
Javascript :: ... in javascript 
Javascript :: js includes case insensitive 
Javascript :: module.exports equivalent typescript 
Javascript :: angular 9 features 
Javascript :: filter bootstrap 
Javascript :: how to turn a string into an array javascript 
Javascript :: adding int and string in react props 
Javascript :: mongoose id validator 
Javascript :: Auto increment in firebase realtime database 
Javascript :: set method in javascript 
Javascript :: how to include bootstrap in react 
Javascript :: check cookie existence js 
Javascript :: what is lodash omitBy 
Javascript :: JS longest word 
Javascript :: ssl certificate nodejs 
Javascript :: trigger jquery autocomplete on click 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =