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 Sledge

Greetings All! I am trying to get a bit of code running. I have attached two excerpts from \game\entities\player.js. I define my animations as follows:

setupAnimation: function( offset ) {
	offset = offset * 10;
	this.addAnim('idle', 1, [0+offset] );
	this.addAnim('run', .07, [0+offset,1+offset,2+offset,3+offset,4+offset,5+offset] );
	this.addAnim('jump', 1, [9+offset] );
	this.addAnim('fall', .4, [6+offset,7+offset] );
},	

I then call inside of the update() method:


this.setupAnimation(this.weapon);

if( this.vel.y <0 ) {
	this.currentAnim = this.anims.jump;
}else if( this.vel.y > 0) {
	this.currentAnim = this.anims.fall;
}else if( this.vel.x != 0 ) {
	this.currentAnim = this.anims.run.rewind();
}else{
	this.currentAnim = this.anims.idle;
}

Some of you may recognize this code from Jesse Freeman's book. The problem I am having is that none of the animations appear to animate! Each is stuck on the first frame. Otherwise the game runs fine and there are no errors in the console.

I would greatly appreciate any insight into this matter.

1 decade ago by mglnunez

I see 2 things.

First: You are setting up your animations every frame.
So when you switch the currentAnim it is using the newly created animations and will always start in the first frame.

Second: When you fix that first problem your 'run' animation will rewind every frame.

So you don't want to create new animations every frame and you don't want to rewind an animation every frame.
I would not change the currentAnim every frame either.

1 decade ago by Sledge

Thank you much, that fixed it!
Page 1 of 1
« first « previous next › last »