C++ Cocos2d-x box2d应用程序强制方向
如何对箭头精灵方向施加力?我需要应用箭头旋转C++ Cocos2d-x box2d应用程序强制方向,c++,cocos2d-x,C++,Cocos2d X,如何对箭头精灵方向施加力?我需要应用箭头旋转 谢谢。这里有一种方法: 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_RAD
谢谢。这里有一种方法:
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);
这里有一种方法:
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);