Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zacware

macrumors member
Original poster
Jul 24, 2002
41
11
Just thought I would post this in case it is of help to anyone. I was working with the 3 excellent graphics libraries for the iPhone (CoCos2d, Chipmunk & SpaceManager), but one problem I had was creating physics segments to match my terrain so that objects would follow the terrain accurately.

So I wrote a little demo file that shows how I solved my issue. The demo shows how you can use code to "trace" a PNG file and then automatically generate an array of segments that can be used to make a matching set of physics shapes so that for instance if you drop a ball from the sky, it will land on the terrain and follow it accurately and realistically.

Just thought I would share the code in case it saves anyone else some time.

http://steveweintraut.blogspot.com/2010/04/2d-terrain-mapper-for-use-with-iphone.html

This demo works on both the iphone and ipad using the 3.2 SDK so if you have an older version of the SDK you will have to strip out the ipad specific code.

Enjoy
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.