Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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.

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;
			}
		}	
	});
});

1 decade ago by Joncom

Firstly, it&039;s much easier to read your code if you enclose the code in # characters.

Like this:
##
// some code here
var foo = function() {
return 'bar';
}
##

Result:
// some code here
var foo = function() {
    return 'bar';
}

And as for the answer to your question, things should work properly again once you include the line this.parent(); inside your update method.

The reason it's happening is because the parent call is where the animation update takes place.

Good luck.

1 decade ago by pangyan

It worked! Impact is a great framework. I think as a Ruby on Rails programmer, I especially like how it has a convention that makes it easier to work with it.
Page 1 of 1
« first « previous next › last »