Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser aseprite animation

function preload ()
{
    this.load.path = 'assets/animations/aseprite/';

    this.load.aseprite('paladin', 'paladin.png', 'paladin.json');
}

function create ()
{
    var tags = this.anims.createFromAseprite('paladin');

    var sprite = this.add.sprite(500, 300).play({ key: 'Magnum Break', repeat: -1 }).setScale(6);

    for (var i = 0; i < tags.length; i++)
    {
        var label = this.add.text(32, 32 + (i * 16), tags[i].key, { color: '#00ff00' });

        label.setInteractive();
    }

    this.input.on('gameobjectdown', function (pointer, obj) {

        sprite.play({
            key: obj.text,
            repeat: -1
        });

    });

    this.input.on('gameobjectover', function (pointer, obj) {

        obj.setColor('#ff00ff');

    });

    this.input.on('gameobjectout', function (pointer, obj) {

        obj.setColor('#00ff00');

    });
}
Comment

phaser create animation on sprite

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

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

        const rambo = this.add.sprite(500, 500, 'soldier');

        //  The following animation is created directly on the 'rambo' Sprite.

        //  It cannot be used by any other sprite, and the key ('walk') is never added to
        //  the global Animation Manager, as it's kept local to this Sprite.
        rambo.anims.create({
            key: 'walk',
            frames: this.anims.generateFrameNames('soldier', { prefix: 'soldier_3_walk_', start: 1, end: 8 }),
            frameRate: 12,
            repeat: -1
        });

        //  Now let's create a new 'walk' animation that is stored in the global Animation Manager:
        this.anims.create({
            key: 'walk',
            frames: this.anims.generateFrameNames('soldier', { prefix: 'Soldier_2_walk_', start: 1, end: 8 }),
            frameRate: 12,
            repeat: -1
        });

        //  Because the rambo Sprite has its own 'walk' animation, it will play it:
        rambo.play('walk');

        //  However, this Sprite will play the global 'walk' animation, because it doesn't have its own:
        this.add.sprite(200, 500, 'soldier')
            .play('walk');
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: register service worker 
Javascript :: type conversions in javascript 
Javascript :: remove string character in center javascript 
Javascript :: datepicker auto select off 
Javascript :: how to create an async function from a string in node js 
Javascript :: appregistry react native 
Javascript :: lodash isequal 
Javascript :: custom hook 
Javascript :: the rest operator javascript 
Javascript :: react-phone-number-input properties 
Javascript :: loadstring json flutter 
Javascript :: canvas rounded corners 
Javascript :: jquery public function 
Javascript :: push notification react native 
Javascript :: js how to to attach an event handler only once 
Javascript :: js addeventlistener keyup android 
Javascript :: split 
Javascript :: axios post data vue js 
Javascript :: angular 12 features 
Javascript :: leafletjs code 
Javascript :: jquery creating several items 
Javascript :: Change HTML Content 
Javascript :: jquery validation date min max 
Javascript :: mongoose get elements that contain substring 
Javascript :: capitalize first letter of a string 
Javascript :: contextMenus chrome extensions 
Javascript :: even.target in javascript 
Javascript :: of() angular 
Javascript :: pagination.js cdn 
Javascript :: axios put request 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =