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 anaish

Hi, I've noticed that the Box2d plugin's body class does not contain a method called SetAngle(<number>). I would like to rotate one of my box2d entities (and it's related animation). After looking through the forums I have tried the following:

//this is part of the update() function in my box2dentity
this.anims.idle.angle += 0.17;
this.body.angle += 0.17;

//call update
this.parent();


The problem is that the call to this.parent() sets the body.angle property to that of this.body.GetAngle() which is always 0. See /lib/plugins/box2d/entity.js line 52 in the physics demo.

How do you rotate both an animation and its related body?

1 decade ago by alexandre

Add this function to your Entity class (extends ig.Box2DEntity):

rotateTo: function (degrees)
{
	this.anims.idle.angle += degrees.toRad();
	this.body.SetXForm(this.body.GetPosition(), degrees.toRad());
},

1 decade ago by anaish

thank you!
Page 1 of 1
« first « previous next › last »