开发者

How to simulate gravity for CCSprite?

开发者 https://www.devze.com 2023-04-11 13:24 出处:网络
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 mu

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 shou开发者_Python百科ld 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号