ui20dev Posted March 2, 2014 Share Posted March 2, 2014 So I am just 1 day into phaser and javascript and I hit my first bump. I followed this tutorial for my own little project. Trying to learn the pragmatic way. http://blog.lessmilk.com/how-to-make-flappy-bird-in-html5-1/ I am having problems showing the idle animation, the game runs in this state. The sprite is showing but has no animation. // Initialize Phaser, and creates a 400x490px gamevar game = new Phaser.Game(480, 800, Phaser.AUTO, 'game_div'); // Creates a new 'main' state that will contain the gamevar main_state = { preload: function() { // Function called first to load all the assets this.game.stage.backgroundColor = '#4f90cd'; this.game.load.spritesheet('doubleflappy', 'assets/characters.png', 54, 42); }, create: function() { // Fuction called after 'preload' to setup the game this.flappytest = this.game.add.sprite(100, 350, 'flappytest'); this.animations.add('flapping', [0, 1, 2], 3, true); this.animations.start('flapping'); //I think something is wrong with this line }, update: function() { // Function called 60 times per second },}; // Add and start the 'main' state to start the gamegame.state.add('main', main_state); game.state.start('main'); Also, how do you properly display code on this forum? Link to comment Share on other sites More sharing options...
rich Posted March 2, 2014 Share Posted March 2, 2014 Here this might help: http://docs.phaser.io/Phaser.AnimationManager.html#toc18 Link to comment Share on other sites More sharing options...
Magnifisite Posted March 2, 2014 Share Posted March 2, 2014 this.flappytest = this.game.add.sprite(100, 350, 'flappytest');this.flappytest.animations.add('flapping', [0, 1, 2], 3, true);this.flappytest.animations.start('flapping'); //I think something is wrong with this lineYou have to add the animation to the sprite and start the animation on that sprite. Link to comment Share on other sites More sharing options...
ui20dev Posted March 3, 2014 Author Share Posted March 3, 2014 this.flappytest = this.game.add.sprite(100, 350, 'flappytest');this.flappytest.animations.add('flapping', [0, 1, 2], 3, true);this.flappytest.animations.start('flapping'); //I think something is wrong with this lineYou have to add the animation to the sprite and start the animation on that sprite. Oh I thought that is what I did. 'flappying is the animation and flappytest is the sprite... Link to comment Share on other sites More sharing options...
rich Posted March 3, 2014 Share Posted March 3, 2014 The way you added the animation to the sprite is fine. There's just no 'start' method, hence the link I gave you. Link to comment Share on other sites More sharing options...
ui20dev Posted March 4, 2014 Author Share Posted March 4, 2014 oh I tried play as well but same. Would this work without a trigger though? It is an idle animation.I tried play, start etc. The tutorial sued start. Link to comment Share on other sites More sharing options...
rich Posted March 4, 2014 Share Posted March 4, 2014 It's "play", there's no such function as "start" on Phaser.AnimationManager. Other than changing start to play there is nothing wrong in the 3 lines of code you posted, so if it still doesn't animate the issue is coming from somewhere else in your code. Link to comment Share on other sites More sharing options...
ui20dev Posted March 5, 2014 Author Share Posted March 5, 2014 I got it solved, thanks for the help <3 Link to comment Share on other sites More sharing options...
Recommended Posts