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 Jon123

Hi, I want to update an entity's position every time the update() method is called, but calling
this.parent()
resets the position to what it was at the start.

update: function(){
	this.currentAnim = this.anims.left;
	this.pos.x = this.pos.x -1;
	this.parent();
},

If I don't call this.parent(), the animSheet doesn't update and none of the collision detection works, the entity simple floats through walls...

Any help would be appreciated.

1 decade ago by Joncom

Does your entity extend ig.Entity or something else? If something else then it is possible that this.parent() is doing something extra which you would have defined...

1 decade ago by Jon123

It extends Box2DEntity, which I think is just confusing things:

EntityEnemy = ig.Box2DEntity.extend({


I think I will go back to basics a little and work on the JumpNRun game again...

1 decade ago by Joncom

Oh, that makes perfect sense then.

The reason this is happening is because this.pos is somewhat broken in the official Box2D plugin. If you were to use this plugin instead, which is an improved version of the same plugin, you would not be having this issue.

Here's the proper way to set the position with the plugin you're using:
entity.pos.y = 100;
var oldPos = entity.body.GetPosition();
var yScaled = entity.pos.y * Box2D.SCALE;
var newPos = new Box2D.Common.Math.b2Vec2(oldPos.x, yScaled);
entity.body.SetPosition(newPos);

Here's how you'd do it with the plugin I'm recommending:
entity.pos.y = 100;

1 decade ago by Jon123

Ah OK thanks, that makes sense!
Page 1 of 1
« first « previous next › last »