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 Yu

Since I'm an artist so I can only copy and paste, try my very best to digest it. Below is my code copied from pong's source. Keys are binded within main.js.

I'm using the up and down buttons but only the animation runs, the entity itself get stucked at the very same position.

ig.module(
	'game.entities.cutie'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntityCutie = ig.Entity.extend({

	size: {x:32, y:32},
	collides: ig.Entity.COLLIDES.ACTIVE,
	
	animSheet: new ig.AnimationSheet( 'media/cutie.png', 32, 32 ),

	init: function( x, y, settings ) {
		this.addAnim( 'idle', 0.1, [0] );
		this.addAnim( 'up', 0.1, [9,10,11] );
		this.addAnim( 'down', 0.1, [0,1,2] );
		this.addAnim( 'left', 0.1, [3,4,5] );	
		this.parent( x, y, settings );
	},

	update: function() {
	
		if( ig.input.pressed('up') ) {
			this.currentAnim = this.anims.up;
			this.vel.y = -100;			
		}
		else if( ig.input.pressed('down') ) {
			this.currentAnim = this.anims.down;	
			this.vel.y = 100;	
		}
		else {
			this.vel.y = 0
		}
		
		this.parent();	
	}	
});

1 decade ago by Yu

Updated: found the solution by changing ig.input.pressed to ig.input.state.

How if I were to add in left and right buttons? And to have the animation switch back to idle (single frame) when a player released the button?

1 decade ago by Hareesun

I'm just about to run out the door, but you should look at the Jump'N'Run demo/source. It show's what your after on the player.entity

1 decade ago by Yu

Thanks for the pointer, I've got it working finally. I'm starting to fall in love with the community, every (dummy) answers I asked got answered.

Will update my game in the game section when I got it started.

1 decade ago by Hareesun

Quote from Yu
Thanks for the pointer, I've got it working finally. I'm starting to fall in love with the community, every (dummy) answers I asked got answered.

Will update my game in the game section when I got it started.


I don't know if you've considered it, but you might find that having animations change depending on the direction the player is moving works better. Rather than the direction pressed. Doing this I've found stops some animation jittering when hitting several keys at once. Something like this...

if (this.vel.x > 0) {
  // if the entity is moving on the x-axis more than 0 do this...
  this.currentAnim = this.anims.run;
}

1 decade ago by Yu

nope I didn't think about using the axis directional at all. That's why I've found some animation jitter too.

btw, I've tried your method on my entity but my character won't move. Am I missing anything here?

1 decade ago by Hareesun

Yup. You'll still need to have the "when this key is pressed make the players vel.x go up" thing. That's just a sample. :)

1 decade ago by Yu

i go it now then, thanks!
Page 1 of 1
« first « previous next › last »