Jump to content

JSON object


DeadGreat
 Share

Recommended Posts

Hey all !

 

 

I've a problem with my animation JSON..
 
main.js
function preload() {    game.load.image('background', 'assets/games/background.jpeg');    game.load.atlas('chick', 'assets/games/chick.png', 'data/chick.JSON');}var player;var bg;function create() {    bg = game.add.tileSprite(0, 0, 800, 600, 'background');    player = game.add.sprite(0, 138, 'chick');    player.animations.add('fly', [1,2,3]);    player.animations.play('fly', 3, true);}

chick.JSON

{"frames": [	{		"name": "fly01",		"frame": {"x":0,"y":0,"w":138,"h":34}	},	{		"name": "fly02",		"frame": {"x":43,"y":0,"w":138,"h":34}	},	{		"name": "fly03",		"frame": {"x":90,"y":0,"w":138,"h":34}	}]}
With the animations added, i've a black screen but with a image, all works fine.
 
 
Link to comment
Share on other sites

Try changing line 14 to:

player.animations.add('fly', ['fly01','fly02','fly03']);

This is because the frames are named rather than indexed. Also, if they were indexed remember they start at 0, so it should be [0, 1, 2]. Also check your console to see if there are any errors, there usually will be if you've done something wrong.

Link to comment
Share on other sites

so i am not an expert. But what i can see is the following:

    game.load.atlas('chick', 'assets/games/chick.png', 'data/chick.JSON');

I load my animation for the player and enemies as:

game.load.spritesheet('dude', 'assets/dude.png', 32, 48);

I use the code and example from the example.phaser.io

This part goes in the create function part       // The player and its settings    player = game.add.sprite(32, game.world.height - 150, 'dude');    //  We need to enable physics on the player    game.physics.arcade.enable(player);    //  Player physics properties. Give the little guy a slight bounce.    player.body.bounce.y = 0.2;    player.body.gravity.y = 300;    player.body.collideWorldBounds = true;    //  Our two animations, walking left and right.    player.animations.add('left', [0, 1, 2, 3], 10, true);    player.animations.add('right', [5, 6, 7, 8], 10, true);   

Then in the update function

    game.physics.arcade.collide(player, layer);    //  Reset the players velocity (movement)    game.physics.arcade.overlap(player, stars, collectStar, null, this);        player.body.velocity.x = 0;    if (cursors.left.isDown)    {        //  Move to the left        player.body.velocity.x = -150;        player.animations.play('left');    }    else if (cursors.right.isDown)    {        //  Move to the right        player.body.velocity.x = 150;        player.animations.play('right');    }    else    {        //  Stand still        player.animations.stop();        player.frame = 4;    }        //  Allow the player to jump if they are touching the ground.    if (cursors.up.isDown)    {        if(player.body.onFloor()){                   player.body.velocity.y = -320;               }    }

Hope this helps

 

I am not familar with atlas yet. However you can check an example on:

 

 

http://examples.phaser.io/_site/view_full.html?d=animation&f=looped+animation.js&t=looped%20animation

 

http://examples.phaser.io/_site/view_full.html?d=animation&f=local+json+object.js&t=local%20json%20object

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...