What is Chipmunk? (Apart from being a Physics Engine)

点点圈 提交于 2019-12-02 00:48:47

问题


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



来源:https://stackoverflow.com/questions/715149/what-is-chipmunk-apart-from-being-a-physics-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!