Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Cocos2d-x box2d应用程序强制方向_C++_Cocos2d X - Fatal编程技术网

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