Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser tween timescale

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.bg = this.add.tileSprite(0, 16, 800, 600, 'bg').setOrigin(0);
        this.ground = this.add.tileSprite(0, 536, 800, 64, 'tiles', 1).setOrigin(0);

        this.add.text(400, 8, 'Tweening the Animation.timeScale', { color: '#ffffff' }).setOrigin(0.5, 0);

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

        this.anims.create(runConfig);

        this.lancelot = this.add.sprite(480, 536, 'knight');

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

        this.tweens.add({
            targets: this.lancelot.anims,
            timeScale: { from: 0.5, to: 2 },
            ease: 'Sine.inOut',
            yoyo: true,
            repeat: -1,
            repeatDelay: 1000,
            hold: 1000,
            duraton: 3000
        });
    }

    update() {
        this.bg.tilePositionX += 3 * this.lancelot.anims.timeScale;
        this.ground.tilePositionX += 6 * this.lancelot.anims.timeScale;
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: regular expression a-z and 0-9 
Javascript :: javascript multiplication without operator 
Javascript :: .every() Accepts a test function and returns a boolean if all the elements of the array pass the test. 
Javascript :: como usar variables en selector jquery 
Javascript :: Exercice âge JavaScript 
Javascript :: remove text in div JQuery zqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq 
Javascript :: nodejs where multiple condition findAll 
Javascript :: Expresion regular para validar nombres de usuario 
Javascript :: reactjs moment to string 
Javascript :: find numeric Unicode value of the character with charCodeAt() method 
Javascript :: nestjs TS2339 
Javascript :: mogoose schema to add json as a property 
Javascript :: express-js 
Javascript :: format numbers js 
Javascript :: empty array javascript 
Javascript :: js brightness 
Javascript :: useselector 
Javascript :: nextjs app 
Javascript :: mongoose remove 
Javascript :: how to do subtraction in javascript 
Javascript :: javascript callback function 
Javascript :: react-native spinner 
Javascript :: how to unfreeze object in javascript 
Javascript :: javascript exeit from loop 
Javascript :: how to remove an element from an array javascript 
Javascript :: Adding an item to an array 
Javascript :: how to display message in javascript 
Javascript :: get sessionstorage value in jquery 
Javascript :: react.createref 
Javascript :: how to name a file path in document.geteleementbyid 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =