如何对箭头精灵方向施加力?我需要申请箭头旋转。
感谢。
答案 0 :(得分:0)
这是一种方法:
cocos2d::Sprite* arrow = ... // defined here
b2Body* body = ... // defined here
// Get the arrow rotation in cocos2d world (deg), and transform it to Box2D world (rad).
float angle = CC_DEGREES_TO_RADIANS(-1 * arrow->getRotation());
// Set the magnitude of the force. It can be any positive number.
float mag = 1;
// Calculate the force vector.
b2Vec2 force(mag * cosf(angle), mag * sinf(angle));
body->ApplyForceToCenter(force, true);