1 decade ago by LazerFriends
I'm converting to Box2D Sugar, and my player entity won't move if left idle for a second.
If you press the movement keys right away, it moves just fine, but won't if you let go for a second.
I have a feeling its something very simple, so apologies for the n00b question.
Here's the link: http://bsmallbeck.com/impact/
Here's the code:
If you press the movement keys right away, it moves just fine, but won't if you let go for a second.
I have a feeling its something very simple, so apologies for the n00b question.
Here's the link: http://bsmallbeck.com/impact/
Here's the code:
ig.module( 'game.entities.player' ) .requires( 'impact.entity', 'plugins.joncom.box2d.entity' ) .defines(function(){ EntityPlayer = ig.Entity.extend({ size: {x:34, y:56}, offset: {x: 1, y: 14}, maxVel: {x: 200, y: 250}, type: ig.Entity.TYPE.A, checkAgainst: ig.Entity.TYPE.NONE, collides: ig.Entity.COLLIDES.NEVER, animSheet: new ig.AnimationSheet( 'media/player.png', 36, 72), flip: false, zIndex:2, isFixedRotation:true, init: function( x, y, settings){ this.parent(x,y,settings); this.addAnim( 'idle', 1, [0]); this.addAnim( 'run', .11, [1,2,3,4,5,6,7,8] ); this.addAnim( 'jump', 1, [9] ); this.addAnim( 'fall', 1, [9] ); }, update: function(){ if( ig.input.state('forward')){ this.vel.x += 200; this.flip = false; } else if( ig.input.state('back')){ this.vel.x -= 200; this.flip = true; } else { this.vel.x = 0; } 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 { this.currentAnim = this.anims.idle; } this.currentAnim.flip.x = this.flip; this.parent(); } }); });