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 Gamma

Hello everyone, recently I've been thinking of making the character go backwards as an in-game tactic, but I've been having trouble with that. First I made a little bit of code in the Main.js file.

ig.input.bind( ig.KEY.Z, 'backwards');

Then I continued on, and added a strip of code to the player.js file, like so [Under the init function,].

this.addAnim( 'defense', 0.07, [16,17]);

But my problem is, how would I make it so that when the user presses on the Z key, the player would move backwards (left) on the screen. I currently was able to make it flip backwards, but the animation wouldn't show up.

This is what I added to make it flip, but no animation showed up. [Under the update function]

// Moving Backwards (Defense tactic)
			var accel = this.standing ? this.accelGround : this.accelAir;
			if( ig.input.pressed('backwards') ) {
               this.accel.x = -accel;
        		this.flip = true;

[EDIT]

Ok, so I got it to work so that when the user presses Z the player moves left, BUT the animation won't show.

var accel = this.standing ? this.accelGround : this.accelAir;
			if( ig.input.state('backwards') ) {
        		this.accel.x = -accel;
        		this.flip = true;
			}

1 decade ago by Heartless49

you need to add the line of code telling the entity to play the animation.

this.currentAnim = this.anims.backwardsAnimationName;

that's how to have an entity actually play the animations that you made, otherwise it doesn't know to play/show anything.

1 decade ago by Gamma

I know what you mean, but what condition should I give the animation?


 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( [//What would I add here?]) { // The backwards animation 
            	this.currentAnim = this.anims.backwards;	   
            }else{
            	this.currentAnim = this.anims.idle;
            }
            this.currentAnim.flip.x = this.flip;
        	// move!
        	this.parent();
        },

1 decade ago by Heartless49

Oh I see, you're basing the animations on the velocity. You would need to change around how you're doing the animations. I'm not exactly sure how your gameplay is, in terms of movement, but it would depend on the input and how the player moves.

1 decade ago by Gamma

The game is a side-scroller, and I don't really know what other ways to handle animation, I think I might just make experiments for a bit.

1 decade ago by Joncom

Quote from Gamma
The game is a side-scroller, and I don't really know what other ways to handle animation, I think I might just make experiments for a bit.

It might work doing it the way you are, but some people would consider it better practice to set the animation each time a key is pressed. That way, you're usually doing it about once per key-press, instead of on every update.

1 decade ago by quidmonkey

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.backwards;       
}
else if( this.vel.x > 0 ) {
    this.currentAnim = this.anims.run;    
}
else{
    this.currentAnim = this.anims.idle;
}
this.currentAnim.flip.x = this.flip;

1 decade ago by Gamma

Thanks guys, it worked now.

1 decade ago by Heartless49

Quote from Joncom
It might work doing it the way you are, but some people would consider it better practice to set the animation each time a key is pressed. That way, you're usually doing it about once per key-press, instead of on every update.


I actually think doing it by motion is pretty smart - I've never tried it, but I like the idea of if the player is falling and no is being pressed, it plays the falling animation. It would just need a.little fine tuning because I do agree that I wouldn't want it being called every frame.

Otherwise, great idea, ^^
Page 1 of 1
« first « previous next › last »