3

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

gargantuan
  • 8,670
  • 14
  • 63
  • 105

2 Answers2

2

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
  • 99,195
  • 24
  • 125
  • 135
  • 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? – gargantuan Apr 03 '09 at 18:51
  • 1
    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 Apr 03 '09 at 18:59
  • 1
    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 Apr 03 '09 at 19:00
1

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
  • 11
  • 1