Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser pause all animations

  preload ()
    {
        this.load.atlas('soldier', 'assets/animations/soldier.png', 'assets/animations/soldier.json');
        this.load.image('bg', 'assets/skies/grass.jpg');
    }

    create ()
    {
        this.add.image(400, 300, 'bg');
        this.add.text(400, 32, 'Click to pause all animations', { color: '#ffffff' }).setOrigin(0.5, 0);

        this.anims.create({
            key: 'shoot1',
            frames: this.anims.generateFrameNames('soldier', { prefix: 'Soldier_2_shot_up_', start: 1, end: 11 }),
            frameRate: 10,
            repeat: -1
        });

        this.anims.create({
            key: 'shoot2',
            frames: this.anims.generateFrameNames('soldier', { prefix: 'soldier_3_shoot_front_', start: 1, end: 11 }),
            frameRate: 10,
            repeat: -1
        });

        //  Generate some random toy soldiers
        for (let i = 0; i < 32; i++)
        {
            const x = Phaser.Math.Between(0, 800);
            const y = Phaser.Math.Between(200, 550);
            const rd = Phaser.Math.Between(200, 2000);
            let troop;

            if (i < 16)
            {
                troop = this.add.sprite(x, y, 'soldier', 'Soldier_2_shot_up_1');
                troop.setDepth(y);

                troop.playAfterDelay({ key: 'shoot1', repeatDelay: rd }, rd);
            }
            else
            {
                troop = this.add.sprite(x, y, 'soldier', 'soldier_3_shoot_front_1');
                troop.setDepth(y);

                troop.playAfterDelay({ key: 'shoot2', repeatDelay: rd }, rd);
            }
        }

        this.input.on('pointerdown', function () {
            //  Every single animation in the Animation Manager will be paused:
            if (this.anims.paused)
            {
                this.anims.resumeAll();
            }
            else
            {
                this.anims.pauseAll();
            }
        }, this);
    }
Comment

phaser pause animation instances

 preload ()
    {
        this.load.atlas('gems', 'assets/tests/columns/gems.png', 'assets/tests/columns/gems.json');
    }

    create ()
    {
        this.add.text(400, 32, 'Click to pause all Square animation instances', { color: '#00ff00' }).setOrigin(0.5, 0);

        const diamond = this.anims.create({ key: 'diamond', frames: this.anims.generateFrameNames('gems', { prefix: 'diamond_', end: 15, zeroPad: 4 }), repeat: -1 });
        const prism = this.anims.create({ key: 'prism', frames: this.anims.generateFrameNames('gems', { prefix: 'prism_', end: 6, zeroPad: 4 }), repeat: -1 });
        const ruby = this.anims.create({ key: 'ruby', frames: this.anims.generateFrameNames('gems', { prefix: 'ruby_', end: 6, zeroPad: 4 }), repeat: -1 });
        const square = this.anims.create({ key: 'square', frames: this.anims.generateFrameNames('gems', { prefix: 'square_', end: 14, zeroPad: 4 }), repeat: -1 });

        //  square added twice just to make sure there are more of them
        const keys = [ 'diamond', 'prism', 'ruby', 'square', 'square' ];

        let x = 100;
        let y = 116;

        for (let i = 0; i < 35; i++)
        {
            this.add.sprite(x, y, 'gems').play(keys[Phaser.Math.Between(0, 4)]);

            x += 100;

            if (x === 800)
            {
                x = 100;
                y += 100;
            }
        }

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

            //  Every sprite using the global 'square' animation will now pause,
            //  because we're pausing the Animation instance itself:

            if (square.paused)
            {
                square.resume();
            }
            else
            {
                square.pause();
            }

        });
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser play animation with config.js 
Javascript :: phaser animation show on start 
Javascript :: Counting Duplicates 
Javascript :: test unitaire javascript 
Javascript :: unicons add all icons 
Javascript :: Exercice âge JavaScript 
Javascript :: remove text and keep div inside a div jquery 2 
Javascript :: object destructuring in javascript 
Javascript :: hook use effect with class 
Javascript :: nodejs mongodb native reuse single connection 
Javascript :: site:stackoverflow.com two api calls dependent on each other js 
Javascript :: show fist 100 character use js 
Javascript :: js replay animation 
Javascript :: × error: element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. you likely forgot to export your component from the file it 
Javascript :: ternary operators js 
Javascript :: how to call function from another component in vue js 
Javascript :: sorting an array 
Javascript :: map method in javascript 
Javascript :: Multiple functions in javascript onclick 
Javascript :: Filtering an array for unique values 
Javascript :: is multiple select javascript 
Javascript :: mongoose update array push multiple 
Javascript :: copy folder in nodejs 
Javascript :: get the max value from array js 
Javascript :: javascript error handling 
Javascript :: javascripts events 
Javascript :: create a node 
Javascript :: moment-recur cdn 
Javascript :: javascript casting objects 
Javascript :: array of array of string js 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =