Using a Layer Mask for advanced collision shapes

Discuss new features and future development.
Post Reply
anthonyhsiao
Posts: 1
Joined: Tue May 31, 2011 11:46 am
Contact:

Using a Layer Mask for advanced collision shapes

Post by anthonyhsiao »

Hey,

I read in the documentation that it is possible to mask a layer (e.g. using a black and white image turned bit-map of 1s and 0s), and that shapes only collide if they are in the same bit-planes.

NOW, I have a use case where there is a rather complex 'environment' that I want to navigate a ball through. Imagine a cave or something like that with rather unconvex walls (in 2D, from an above-perspective) through which I want to navigate a ball, and of course, have the ball collide with the wall of the cave.

I was wondering, is it possible to just define a large rectangle that comprises the entire 'space', and mask that rectangle with a black/white image that actually has a more complicated shape that I would rather not have to draw using any of the given shapes, and then put the ball inside that rectangle, and it'll only collide with areas of the rectangle that have not been masked away?

Is that possible?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Using a Layer Mask for advanced collision shapes

Post by slembcke »

No. Unfortunately you are confusing bitmasks with image masks. (http://en.wikipedia.org/wiki/Mask_(computing)) When using an image mask to draw something, you can use bitmasks to implement it.

A bitmask is just a binary number. The bits that are 1 are the layers that a shape is in. So if you had a shape with the mask (in binary) 1001 and another shape with the mask 0110, they would not collide because they aren't in any of the same layers.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests