Using a Layer Mask for advanced collision shapes
Posted: Tue May 31, 2011 12:05 pm
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?
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?