如何在箭头精灵方向上施加力?我需要应用箭头旋转。

谢谢。

最佳答案

这是一种实现方法:

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);

关于c++ - Cocos2d-x box2d施加力方向,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35917737/

10-13 04:37