1 decade ago by igr
Hello good people!
I have a problem which I do not quite understand. Hero in my game have shooting animation both standing and in duck position. I have the following code in my update function for animation based on Hero's speed:
The problem is when I press 'C' for shoot either in standing or "duck" position the animation does always play. It works randomly: sometimes it does and sometimes it does not. And I do not understand why. Any ideas? Thank you!
I have a problem which I do not quite understand. Hero in my game have shooting animation both standing and in duck position. I have the following code in my update function for animation based on Hero's speed:
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;
}
else if (this.vel.x == 0 && ig.input.state('duck')){
// Different offset, when ducked
this.size.y = 78;
this.offset.y = 44;
if (ig.input.pressed('shoot')){
this.currentAnim = this.anims.shootduck;
} else{
this.currentAnim = this.anims.duck;
}
}
else if( ig.input.pressed('shoot') && this.vel.x == 0){
this.currentAnim = this.anims.shoot;
}
else{
// Back to standing offset. Might be more elegent way to code.
this.size.y = 115;
this.offset.y = 8;
this.currentAnim = this.anims.idle;
}
The problem is when I press 'C' for shoot either in standing or "duck" position the animation does always play. It works randomly: sometimes it does and sometimes it does not. And I do not understand why. Any ideas? Thank you!
