Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser create animation from texture atlas

 preload ()
    {
        this.load.atlas('sea', 'assets/animations/seacreatures_json.png', 'assets/animations/seacreatures_json.json');

        //  Just a few images to use in our underwater scene
        this.load.image('undersea', 'assets/pics/undersea.jpg');
        this.load.image('coral', 'assets/pics/seabed.png');
    }

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

        //  Create the Animations
        //  These are stored globally, and can be used by any Sprite

        //  In the texture atlas the jellyfish uses the frame names blueJellyfish0000 to blueJellyfish0032
        //  So we can use the handy generateFrameNames function to create this for us (and so on)
        this.anims.create({ key: 'jellyfish', frames: this.anims.generateFrameNames('sea', { prefix: 'blueJellyfish', end: 32, zeroPad: 4 }), repeat: -1 });
        this.anims.create({ key: 'crab', frames: this.anims.generateFrameNames('sea', { prefix: 'crab1', end: 25, zeroPad: 4 }), repeat: -1 });
        this.anims.create({ key: 'octopus', frames: this.anims.generateFrameNames('sea', { prefix: 'octopus', end: 24, zeroPad: 4 }), repeat: -1 });
        this.anims.create({ key: 'purpleFish', frames: this.anims.generateFrameNames('sea', { prefix: 'purpleFish', end: 20, zeroPad: 4 }), repeat: -1 });
        this.anims.create({ key: 'stingray', frames: this.anims.generateFrameNames('sea', { prefix: 'stingray', end: 23, zeroPad: 4 }), repeat: -1 });

        const jellyfish = this.add.sprite(400, 300, 'seacreatures').play('jellyfish');
        const bigCrab = this.add.sprite(550, 480, 'seacreatures').setOrigin(0).play('crab');
        const smallCrab = this.add.sprite(730, 515, 'seacreatures').setScale(0.5).setOrigin(0).play('crab');
        const octopus = this.add.sprite(100, 100, 'seacreatures').play('octopus');
        const fish = this.add.sprite(600, 200, 'seacreatures').play('purpleFish');
        const ray = this.add.sprite(100, 300, 'seacreatures').play('stingray');

        this.add.image(0, 466, 'coral').setOrigin(0);
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser enable pixel art 
Javascript :: phaser mixed animation 
Javascript :: phaser animation on update event 
Javascript :: phaser show animation play through js 
Javascript :: get lat long react native 
Javascript :: Horizontal scroll to anchor 
Javascript :: javascript accordion 
Javascript :: remove text and keep div inside a div jquery 2 
Javascript :: white when respons show code 
Javascript :: ray intersection js 
Javascript :: docker for node , exoress and coackraz 
Javascript :: javascript change IFormFile to base64string 
Javascript :: moment js with nodejs 
Javascript :: string concat in js 
Javascript :: js convert string to number 
Javascript :: fibonacci sequence array 
Javascript :: export default function react 
Javascript :: check if is array javascript 
Javascript :: what is closures in javascript 
Javascript :: javascript unicode character 
Javascript :: vanilla js 
Javascript :: setting up react on visual studio code 
Javascript :: create slice redux 
Javascript :: Difference Between for...of and for...in Statement 
Javascript :: .unshift 
Javascript :: how to detect a section is visible in jquery 
Javascript :: object methods 
Javascript :: TypeError: error.status is not a function 
Javascript :: change string with string js 
Javascript :: for of loop in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =