Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

phaser export animation to json

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

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

        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');

        //  Get a JSON representation of a single animation, or all animations:

        //  You can extract the animation:
        var ruby = this.anims.get('ruby');

        //  Then pass it to JSON.stringify
        console.log(JSON.stringify(ruby));

        //  Or call toJSON directly (this returns an Object)
        console.log(ruby.toJSON());

        //  You can also call 'this.anims.toJSON' and pass it the key of the animation you want:
        console.log(JSON.stringify(this.anims.toJSON('ruby')));

        //  Or dump out ALL animations in the Animation Manager:
        console.log(JSON.stringify(this.anims));
    }
Comment

phaser animation from json

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

    }

    create ()
    {
        this.add.text(400, 32, 'Animations from JSON Object', { color: '#00ff00' }).setOrigin(0.5, 0);

		// here data contains the animation frames information
        this.anims.fromJSON(data);

        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');
    }

const data = {
    "anims": [
        {
            "key": "diamond",
            "type": "frame",
            "frames": [
                {
                    "key": "gems",
                    "frame": "diamond_0000",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0001",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0002",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0003",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0004",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0005",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0006",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0007",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0008",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0009",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0010",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0011",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0012",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0013",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0014",
                    "duration": 0,
                    "visible": false
                },
                {
                    "key": "gems",
                    "frame": "diamond_0015",
                    "duration": 0,
                    "visible": false
                }
            ],
            "frameRate": 24,
            "duration": 1.5,
            "skipMissedFrames": true,
            "delay": 0,
            "repeat": -1,
            "repeatDelay": 0,
            "yoyo": false,
            "showOnStart": false,
            "hideOnComplete": false
        },
    ]}
Comment

PREVIOUS NEXT
Code Example
Javascript :: phaser mixed animation 
Javascript :: phaser animation on start event 
Javascript :: phaser play animation with config.js 
Javascript :: phaser tween timescale 
Javascript :: add multiple phone using js 
Javascript :: refresh secounds 
Javascript :: Pretty-Print JSON within Neovim 
Javascript :: axios imgbb 
Javascript :: Datatable js Search Server side after time or word length 
Javascript :: check notification permissopn allow or not 
Javascript :: nodejs: redirect path to specific path 
Javascript :: nestjs TS2339 
Javascript :: Set A Function For An Element 
Javascript :: js floor a number 
Javascript :: what does the ... mean in javascript 
Javascript :: add line break in innerhtml 
Javascript :: map method 
Javascript :: if else javascript 
Javascript :: mongodb find and update array item by id 
Javascript :: stringbuffer javascript 
Javascript :: in js pass infinite argument in function 
Javascript :: get element by id angular 
Javascript :: download canvas to png 
Javascript :: best way to filter table in angular 
Javascript :: regular expression remove spaces 
Javascript :: add new value to array of object javascript using spread 
Javascript :: sum of a sequence 
Javascript :: Using the Set object 
Javascript :: js upload file size limit 
Javascript :: array function in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =