DeadGreat Posted December 26, 2014 Share Posted December 26, 2014 Hey all ! I've a problem with my animation JSON.. main.jsfunction 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 More sharing options...
lewster32 Posted December 26, 2014 Share Posted December 26, 2014 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 More sharing options...
DeadGreat Posted December 26, 2014 Author Share Posted December 26, 2014 Thanks for your response butplayer.animations.add('fly', ['fly01','fly02','fly03']);or player.animations.add('fly', [0,1,2]);don't work. I've always a black screen. Link to comment Share on other sites More sharing options...
lenlac Posted December 27, 2014 Share Posted December 27, 2014 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.ioThis 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 More sharing options...
DeadGreat Posted December 27, 2014 Author Share Posted December 27, 2014 Hey !Thanks for your response. I've resolved my problem. All works fine. This problem came from my image. Link to comment Share on other sites More sharing options...
Recommended Posts