Jump to content

Animation Using Texture Atlas-Only Playing First Frame


flan
 Share

Recommended Posts

Hello all!  I have hit a roadblock and I need help :/

All I want out of this is one thing: I press a cursor key, and an animation plays.  Three of my animations work perfectly, and two only play the first frame of the animation when the keys are pressed (down && left) || (down && right).  Any insight to what I hope is just a simple typo?  Thanks for your time!

 

EDIT: The frames that are not working are not the same size as the frames that do work, they are about twice the width, could that have something to do with it?

 

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload(){
    
    //loading the background
    game.load.image('background', 'background.png');
    
    //loading three ball images
    game.load.image('redBall', 'redBall.png');
    game.load.image('blueBall', 'blueBall.png');
    game.load.image('greenBall', 'greenBall.png');
    
    //loading the atlas
    game.load.atlas('player', 'henAnimation/henAnimation.png', 'henAnimation/henAnimation.json');
}

var cursors;
var player;

function create(){
    
    //adding the background
    game.add.sprite(0, 0, 'background');
    //adding player
    player = game.add.sprite(200, 200, 'player');
   

//cursor animations-stop, right, and left work perfectly
    player.animations.add('stop', Phaser.Animation.generateFrameNames('', 1, 3, '.png', 4), 10, true);
    player.animations.add('right', Phaser.Animation.generateFrameNames('', 4, 5, '.png', 4), 10, true);
    player.animations.add('left', Phaser.Animation.generateFrameNames('', 6, 7, '.png', 4), 10, true);
   

//only load the first frame of the animation
    player.animations.add('rightlick', Phaser.Animation.generateFrameNames('', 8, 10, '.png', 4), 10, true);
    player.animations.add('leftlick', Phaser.Animation.generateFrameNames('', 11, 13, '.png', 4), 10, true);
    
    cursors = game.input.keyboard.createCursorKeys();
}

function update(){
    if (cursors.left.isDown) {
        player.animations.play('left');
    }
    else if ((cursors.left.isDown) && (cursors.down.isDown)) {
        player.animations.play('leftlick');
    }
    else if (cursors.right.isDown) {
        player.animations.play('right');
    if ((cursors.right.isDown) && (cursors.down.isDown)) {
        player.animations.play('rightlick');
    }
    }
    else {
        player.animations.play('stop');
    }
}

Edited by flan
Added information possibly pertinent to subject and question
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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