1 decade ago by pangyan
I'm creating a turn based dungeon crawler and my animations only show the first frame. When I move the player character, the character turns to the left, right, up or down (the first frame of the animation sheet). But there seems to be no animation.
I do realise that the animation will happen after the player has moved with the code below, but for now I just want to animate the player.
I do realise that the animation will happen after the player has moved with the code below, but for now I just want to animate the player.
ig.module(
'game.entities.player'
)
.requires(
'impact.entity'
)
.defines(function(){
EntityPlayer = ig.Entity.extend({
size: {x: 32, y: 48},
animSheet: new ig.AnimationSheet( 'media/character_1.png', 32, 48 ),
init: function( x, y, settings ) {
// Call the parent constructor
this.parent( x, y, settings );
// Add animations for the animation sheet
this.addAnim( 'up', 0.1, [36, 37, 38] );
this.addAnim( 'down', 0.1, [0, 1, 2] );
this.addAnim( 'left', 0.1, [12, 13, 14] );
this.addAnim( 'right', 0.1, [24, 25, 26] );
this.currentAnim = this.anims.up;
},
update: function(){
// Check for movement with arrow keys
if( ig.input.pressed('up') ) {
console.log("Up");
this.pos.y -= 32;
this.currentAnim = this.anims.up;
}
if( ig.input.pressed('down') ) {
console.log("Down");
this.pos.y += 32;
this.currentAnim = this.anims.down;
}
if( ig.input.pressed('left') ) {
console.log("Left");
this.pos.x -= 32;
this.currentAnim = this.anims.left;
}
if( ig.input.pressed('right') ) {
console.log("Right");
this.pos.x += 32;
this.currentAnim = this.anims.right;
}
}
});
});
