views:

1200

answers:

2

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

+4  A: 

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.

Can Berk Güder
at the risk of oversimplifying something I'm worried might be ridiculously complex, what should I be aware of when mixing C and Objective-C?
gargantaun
I think you should post that as a separate question. I haven't personally mixed C/C++ and Objective-C before, and therefore I'm not aware of any pitfalls.
Can Berk Güder
Objective-C is a superset of C, so there is really no concept of mixing them. They're pre-mixed. Just be aware that the C code is there.
Terry Wilcox
+1  A: 

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

Rob