What is Chipmunk? (Apart from being a Physics Engi

2019-02-25 07:04发布

问题:

Hopefully, this question isn't a dumb as I fear it sounds, but it may still be pretty dumb.

I'm new to Objective-C, and Cocoa. In fact, I'm completely new to C in general. I'm trying to implement an iPhone game using Cocos2d-iPhone. It's a game I've made before in Flash, so I thought it would be a nice way to lean Objective C, cocoa and cocos2d.

One thing I am having a big problem with is understanding why all the Chipmunk code looks different to all the normal Objective-C stuff. For example, there's stuff like

chipmunkBody->position.x

which I thought would have been

chipmunkBody.position.x or maybe [[chipmunkBody position] x] (bad example maybe).

One way this keeps on biting me in the ass is with cpVect. cpVect is pretty important, but I can't for the life of me figure out how to pass it around. CGPoint, no problem, I can make pointers, pass them around in methods and what not, but the second I use cpVect instead, it's "welcome to Errorville, population you".

So that's the question, what is Chipmunk, so I can start finding out more about working with it.

thanks -t

回答1:

I haven't used Chipmunk, but it's probably written in C/C++. That's the reason.

EDIT: Yup, it's written in C.

chipmunkBody is a pointer to a struct, and the arrow operator (->) is how you access the members of a struct through a pointer to the struct in C.



回答2:

In case you're looking for an easy way to use Chipmunk thru way of Objective-C, Theres a nice little post about an Objective-C class called SpaceManager here: http://www.mobile-bros.com/?p=126