Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser play animation after delay

 preload ()
    {
        this.load.atlas('zombie', 'assets/animations/zombie.png', 'assets/animations/zombie.json');
        this.load.image('bg', 'assets/textures/soil.png');
    }

    create ()
    {
        this.bg = this.add.tileSprite(400, 300, 800, 600, 'bg').setAlpha(0.8);
        const text = this.add.text(400, 32, "Click to run playAfterDelay('death', 2000)", { color: '#00ff00' }).setOrigin(0.5, 0);

        //  Our global animations, as defined in the texture atlas
        this.anims.create({ key: 'walk', frames: this.anims.generateFrameNames('zombie', { prefix: 'walk_', end: 8, zeroPad: 3 }), repeat: -1, frameRate: 8 });
        this.anims.create({ key: 'death', frames: this.anims.generateFrameNames('zombie', { prefix: 'Death_', end: 5, zeroPad: 3 }), frameRate: 12 });

        this.rob = this.add.sprite(400, 560, 'zombie').setOrigin(0.5, 1).play('walk');

        this.input.once('pointerdown', function () {
            text.setText('Playing death animation in 2000 ms');

            this.rob.anims.playAfterDelay('death', 2000);

        }, this);
    }

    update ()
    {
        if (this.rob.anims.getName() === 'walk')
        {
            this.bg.tilePositionY++;
        }
    }
Comment

phaser play animation after repeat

preload ()
    {
        this.load.atlas('alien', 'assets/animations/alien.png', 'assets/animations/alien.json');
        this.load.image('bg', 'assets/pics/space-wreck.jpg');
    }

    create ()
    {
        this.add.image(400, 300, 'bg');

        const text = this.add.text(400, 32, "Click to toggle sequence", { color: '#00ff00' }).setOrigin(0.5, 0);

        //  Our global animations, as defined in the texture atlas
        this.anims.create({ key: 'idle', frames: this.anims.generateFrameNames('alien', { prefix: '01_Idle_', end: 17, zeroPad: 3 }), repeat: -1, repeatDelay: 500, frameRate: 18 });
        this.anims.create({ key: 'turn', frames: this.anims.generateFrameNames('alien', { prefix: '02_Turn_to_walk_', end: 3, zeroPad: 3 }), frameRate: 12 });
        this.anims.create({ key: 'walk', frames: this.anims.generateFrameNames('alien', { prefix: '03_Walk_', end: 12, zeroPad: 3 }), repeat: -1, frameRate: 18 });

        const ripley = this.add.sprite(400, 300, 'alien').play('idle');

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

            if (ripley.anims.getName() === 'idle')
            {
                //  When the current animation repeat ends, we'll play the 'turn' animation
                ripley.anims.playAfterRepeat('turn');

                //  And after that, the 'walk' look
                ripley.anims.chain('walk');
            }
            else
            {
                ripley.anims.play('idle');
            }

        });
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser remove animation event 
Javascript :: phaser stagger play 1 
Javascript :: accessing-nested-javascript-objects-and-arrays-by-string-path 
Javascript :: lookbehind alternative regex 
Javascript :: como usar variables en selector jquery 
Javascript :: toast plugin 
Javascript :: JAVASCRIPT CHEATSHEET 1 
Javascript :: white when respons show code 
Javascript :: get random hsl color js 
Javascript :: javascript fiori 
Javascript :: get product 
Javascript :: what is the syntax of putting an event listener in javascript mdn 
Javascript :: offline bot command discord.js 
Javascript :: what is so called abstractions in javascript 
Javascript :: spread 
Javascript :: javascript break with while Loop 
Javascript :: sort array method 
Javascript :: vuejs 
Javascript :: vuejs accessing props from data 
Javascript :: dayjs subtract days 
Javascript :: first element of array js 
Javascript :: monngoose find from an array using in 
Javascript :: chart.js 
Javascript :: react native generate signed apk getting older version 
Javascript :: js flatten 
Javascript :: alertify js examples 
Javascript :: default javascript 
Javascript :: how to clear nodejs terminal in vs code 
Javascript :: python best practices example 
Javascript :: npm mongoose findorcreate 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =