Search code examples
iphonecocos2d-iphonebox2dcollisioncurve

How to create a level with curved lines with cocos2d + Box2d on the iphone?


I'd like to create a game that has levels such as this: http://img169.imageshack.us/img169/7294/picdq.png

The Player moves "flies" through the level and mustn't collide with the walls. How can I create such levels?

I found that piece of software: http://www.sapusmedia.com/levelsvg/

It's not that cheap, so I wonder whether there is another way to create such a level as shown in the picture above...?


Solution

  • You can do that pretty easy by reading the color value of pixels at specific places of the level. Take for instance that your level background is white and the walls are black. In order to perform collision detection, whether your character had hit the wall, you would do the following: -take your character's position -look at the color values of the pixels of your map that overlap with character's bounding box or sphere at that position -if any of those contain black color you have yourself a collision :)

    Now if your level is all colourful, you would want to build a black and white mask texture that would reflect the wall surfaces of your actual map. Then use the coloured map for drawing and the bw map for collision detection.