Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser chained 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, 16, '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 animation chain', { color: '#ffffff' }).setOrigin(0.5, 0);

        //  Our animations
        this.anims.create({
            key: 'guardStart',
            frames: this.anims.generateFrameNames('knight', { prefix: 'guard_start/frame', start: 0, end: 3, zeroPad: 4 }),
            frameRate: 8
        });

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

        this.anims.create({
            key: 'guardEnd',
            frames: this.anims.generateFrameNames('knight', { prefix: 'guard_end/frame', start: 0, end: 3, zeroPad: 4 }),
            frameRate: 8
        });

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

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

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

        lancelot.on(Phaser.Animations.Events.SPRITE_ANIMATION_START, function (anim) {

            text.setText('Playing ' + anim.key);

        });

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

            if (lancelot.anims.getName() === 'idle')
            {
                lancelot.playAfterRepeat('guardStart');
                lancelot.chain([ 'guard', 'guardEnd', 'idle' ]);
            }

        }, this);
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser create animation without frame names 
Javascript :: phaser generate frame names 
Javascript :: phaser animation on start event 
Javascript :: phaser remove animation event 
Javascript :: regular expression a-z and 0-9 
Javascript :: iterate cy.get(') elements 
Javascript :: Who likes it 
Javascript :: remove text in div JQuery zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq 
Javascript :: object destructuring in javascript 
Javascript :: get random hsl color js 
Javascript :: filter text js 
Javascript :: debounce getx 
Javascript :: documentUrlPatterns 
Javascript :: how to run javascript in terminal 
Javascript :: js function expression 
Javascript :: redux-persist 
Javascript :: javascript case insensitive regex 
Javascript :: javascript this = that 
Javascript :: hide and show div using javascript with example 
Javascript :: js functional ajax requests 
Javascript :: what is react easy emoji 
Javascript :: jquery datatable 
Javascript :: javascript.loop 
Javascript :: how to map over arrays vuejs 
Javascript :: array example 
Javascript :: for in loops javascript 
Javascript :: objects 
Javascript :: calculate days between two dates in javascript 
Javascript :: how to write a factorial function in javascript 
Javascript :: currying function callback javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =