1

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 bottom 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.

Rayfleck
  • 12,116
  • 8
  • 48
  • 74

1 Answers1

2

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.

  • thanks for the answer. How would I enable this algorithm? Also, I'm not finding any method call cpBodyIsSleeping(). Do you know if that was added to a recent build? Thanks. – Rayfleck Jun 10 '11 at 21:33
  • Found them [here](http://files.slembcke.net/chipmunk/release/ChipmunkLatest-Docs/) – Rayfleck Jun 14 '11 at 15:28