Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser generate frame names

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

    create ()
    {
        this.add.text(400, 32, 'Check the source code for comments', { color: '#00ff00' }).setOrigin(0.5, 0);

        //  The gems.json file has the following frames in it:

        //  diamond_0000 to diamond_0015

        //  So we use:

        //  generateFrameNames('gems', { prefix: 'diamond_', end: 15, zeroPad: 4 })

        //  Because the prefix is 'diamond_', it has 4 zeros in it (0000), which start at 0000 and end at 0015.

        //  If the frame names had a suffix, i.e. 'diamond_0000.png' then you could do:

        //  generateFrameNames('gems', { prefix: 'diamond_', suffix: '.png', end: 15, zeroPad: 4 })

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

        this.add.sprite(400, 200, 'gems').play('diamond');
        this.add.sprite(400, 300, 'gems').play('prism');
        this.add.sprite(400, 400, 'gems').play('ruby');
        this.add.sprite(400, 500, 'gems').play('square');
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser muy bridge 
Javascript :: phaser animation on update event 
Javascript :: phaser remove animation event 
Javascript :: School paperwork 
Javascript :: share.sharesingle facebook react native 
Javascript :: NodeJS/express : Cached and 304 status code on chrome 
Javascript :: reactjs doc error 
Javascript :: npm deploy next js with tailwind 
Javascript :: js undici fetch data with agent 
Javascript :: using lambda for elasticache node.js 
Javascript :: find numeric Unicode value of the character with charCodeAt() method 
Javascript :: how to target a hidden html element by js 
Javascript :: rpirvate router react 
Javascript :: Slice and Splice -Javascript 2 
Javascript :: shallow copy and deep copy in javascript 
Javascript :: forms in angular 
Javascript :: e.target.value with number 
Javascript :: button as a link react 
Javascript :: react native smart splash screen 
Javascript :: Javascript count instances of character in a string 
Javascript :: javascript post 
Javascript :: get the last item in an array 
Javascript :: unicode in javascript 
Javascript :: javascript how to select a array 
Javascript :: js arrow function vs function 
Javascript :: moment isbetween 
Javascript :: update text react native 
Javascript :: make triangle with threejs 
Javascript :: react fontawesome exchange icon 
Javascript :: update TextInput value react-hook-form react-admin 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =