Jump to content

Noob idle animation problem


ui20dev
 Share

Recommended Posts

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 game
var game = new Phaser.Game(480, 800, Phaser.AUTO, 'game_div');
 
// Creates a new 'main' state that will contain the game
var 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 game
game.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

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 line

You have to add the animation to the sprite and start the animation on that sprite.

Link to comment
Share on other sites

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 line

You 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

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

 Share

  • Recently Browsing   0 members

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