开发者

Cocos2d iPhone Chipmunk sync problem

In my cocos2d-iphone project, I am using Chipmunk to provide a physics model. Additionally, I am using the SpaceManager obj-c wrapper for Chipmunk.

I am giving Chipmunk a constantDt timestep.

Now, the problem I am having is th开发者_开发知识库at the physics simulation is out-of-sync with the game loop. This means that the timings of the gameplay differ depending on the FPS (more specifically, they differ depending on whether I am running it in the simulator, a device, or a newer device).

This has disastrous effects on gameplay. For example, if the FPS slows for some reason, the physics simulation crawls and object move much more slowly. This makes level design near impossible!

Please help!


You could try using two loops in your game. Use NSTimer to stimulate Chipmunk and CADisplayLink only for drawing. On every redraw ask your physics model for current position of objects.


So, I fixed this by using the bleeding edge version of Spacemanager (from source). It has an improved step function (as long as you use a constantDt) that "adds up" any extra time that may have accumulated since the last recalc, and accounts for it.

Thanks MobileBros!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜