c++ - Cocos2d-x box2d applyforce方向

标签 c++ cocos2d-x

如何对箭头 Sprite 方向施加力?我需要使用箭头旋转应用。

谢谢。

最佳答案

这是一种实现方式:

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 applyforce方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35917737/

相关文章:

objective-c - 将 Applovin 集成到 Cocos2d-x iOS 应用程序

ios - 链接器错误 : ld: library not found for -lAppLovinSdk

eclipse - 如何在linux中eclipse上的android项目之前编译.sh

Cocos2d-x 3.0 中的图像资源

c++ - 在 libarchive 中设置 UTF-8 路径名 header

c++ - 将 int 转换为 unsigned long long

c++ - 序列化原始 boost::variant 是否安全?

android - cocos2d-x CCDirector,暂停/恢复 vs stopAnimation/startAnimation

c++ - Qt5迁移: Cannot open include file: 'qtconcurrentexception.h' : No such file or directory

c++ - 如何使用 Clion 或 Netbeans 正确导入 Tensorflow 源代码