Question

When working with pure, unwrapped Box2D and Cocos2D, I used to be able to get the reaction force on a joint with a beautiful function called GetReactionForce. I've recently started trying Sprite Kit physics and I don't seem to find a similar thing. As far as I know there's no ready one. Is there a way I can achieve this in Sprite Kit somehow? The physics engine is still Box2D but not all the capabilities have been made available. I think it could be done using the properties like mass, density, velocity etc. of the bodies forming joint. But I have no idea how.

Était-ce utile?

La solution

It's not readily available and I can't think of a way to emulate or work around it using Sprite Kit's built-in physics.

That said it's fairly easy to just ignore Sprite Kit's physics and instead embed Box2D (or Chipmunk) in your app. You can step the world in the scene's didSimulatePhysics message (gets called even with physicsWorld property being nil). You can store references to nodes inside the body's userData, and after stepping enumerate the bodies and update their node's (obtained from body's userData) position and zRotation properties.

Those are the essential steps. Just because Sprite Kit has physics built-in doesn't mean you can't use other physics engines.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top