Search the Community
Showing results for tags 'animations phaser newbie'.
-
Hello, i'm new to programming and i'm using phaser just for a few days. I'm trying to add a animation to my player, but when i do that, the game crashes. What i'm doing wrong? thats my code: window.onload = function() { var game = new Phaser.Game(800, 400, Phaser.AUTO, '', { preload: preload, create: create, update: update }); var player; function preload () { game.load.atlasJSONHash('walk', 'walk.png', 'walk.json'); game.load.atlasJSONHash('idle', 'idle.png', 'idle.json'); } function create () { //var background = game.add.sprite(0, 0, 'cityscene', 'background'); player = game.add.sprite(0, 325, 'walk', 'walk_0001.png'); player.scale.setTo(0.5,0.5); player.animations.add('walk', Phaser.Animation.generateFrameNames('walk_', 1, 31, '.png', 4), 10, true, false); player.anchor.setTo(.5,.5); player.animations.currentAnim.speed = 30; // Altera velocidade da animação. player.animations.add('idle', Phaser.Animation.generateFrameNames('idle_', 1, 99, '.png', 4), 10, true, false); } function update() { //player.x += 6; if(player.x > 800) { player.x = 0; } else if (player.x < 0){ player.x = 800; } if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { player.scale.setTo(-0.5,0.5); player.animations.play('walk'); player.x -= 4; } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { player.scale.setTo(0.5,0.5); player.x += 4; player.animations.play('walk'); } else { // Stand still //player.animations.play(idle); } // if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) // { // player.y -= 4; // } // else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) // { // player.y += 4; // } } }; I'm trying to add that "idle" animation. Thanks! (I'm not a native english speaker.) Edit: I can normally put the walk animation or the idle animation, when i put both animations, one of them don't work...