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 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:
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!

1 decade ago by BlackDolphinMedia

why not use a stance variable .. what stance your in yet .. if your duck and shoot play .. X if your just shoot play X if you just duck play x ..

i would use a global var to handle that .. symbols plugin which can be found here on the forum handles that well

1 decade ago by igr

Thank you BlackDolphinMedia! Will give it a try. It is indeed much more control with stance variables.

1 decade ago by Kxen

Try:
this.currentAnim = this.anims.shoot.rewind();
Page 1 of 1
« first « previous next › last »