Domanda

In transformPosition method we can apply angle for specific sprite as given below;

[sprite transformPosition:ccpAdd(sprite.position,
ccpMult(ccpForAngle(angle), ANY_VELOCITY))];

Is it possible to use angle and velocity in ApplyLinearImpulse Method's parameter and how? Below is normal declaration of that method. Can we replace that b2Vec2(90, 0) by some angle and velocity as we used above?

body->ApplyLinearImpulse(b2Vec2(90, 0), body->GetWorldCenter());
È stato utile?

Soluzione

Sure, you can do something really similar to what you did up there:

CGPoint angleVector = ccpForAngle(angle);
body->ApplyLinearImpulse(b2Vec2(angleVector.x*ANY_VELOCITY, angleVector.y*ANY_VELOCITY), body->GetWorldCenter());
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top