如何为CCSprite模拟重力?
目前我在我的应用程序中使用 UIKit,但我决定切换到 Cocos2D,现在我正在尝试实现重力,但我遇到了困难。我用谷歌搜索过这个,但没有找到太多关于它的信息。无论如何有什么办法可以做到这一点吗?
有人愿意分享一下他们是如何让 CCSprite 具有重力的吗?我真的不知道我应该从哪里开始如何做到这一点!
谢谢!
编辑1: 我现在使用这段代码:
// Create a world
b2Vec2 gravity = b2Vec2(0.0f, -5.0f);
bool doSleep = true;
_world = new b2World(gravity, doSleep);
对于简单的 y 矢量重力。我的问题是,如何将此代码应用到我的 CCSprite 中?
Currently I am using UIKit in my app but I decided to make the switch to Cocos2D, right now I am trying to implement gravity but I am having trouble doing so. I have googled this and have not found much about it. Anyway is there any way of doing this?
Would anyone like to share what their doing to have a CCSprite have gravity? I really have no idea where I should even begin on how to do this!
Thanks!
Edit1:
I am now using this code:
// Create a world
b2Vec2 gravity = b2Vec2(0.0f, -5.0f);
bool doSleep = true;
_world = new b2World(gravity, doSleep);
For simple y vector gravity. My question is, how would I apply this code to my CCSprite?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,人们使用物理引擎来完成这项工作。 Chipmunk 和 Box2d 都与 cocos2d 捆绑在一起,可以在这方面提供帮助,无需重新发明轮子。
Generally speaking people use physics engines to get this done. Chipmunk and Box2d are both bundled with cocos2d and can help here, no need to reinvent the wheel.