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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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