开发者

How to tell when a sprite has stopped moving

In chipmunk/cocos2d, I have the classic bouncing ball demo happily running with an arbitrary number of balls. How can I tell when a sprite has stopped moving (i.e. the ball has settled to the bot开发者_如何学Gotom and is "done")?

I tried declaring float prevX, prevY in the Layer class, so I could compare current x,y to previous x,y in updateShape, but I can't access the sprite's parent.

         ((CustomLayer *)(sprite->parent))->preX = body->p.x;

The compiler informs me that the sprite's parent is protected.

Thanks.


If you have Chipmunk's sleeping algorithm enabled, you can just call cpBodyIsSleeping().

Chipmunk figures out when things are idle by checking that their kinetic energy is lower than a certain threshold and incrementing a timer. If the timer reaches a certain amount, then it considers the body to be idle.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜