This is also one of the areas that confused me A LOT when I first started with Corona, and really couldn’t find any help anywhere either.
It’s still really confusing, but I got it to work, so I’ll try my best to explain it to you.
First, if you know nothing about bits, binary values, etc. (like me), then shed any kind of logic you possess when trying to figure it out. It simply doesn’t make any logical sense without prior knowledge of binary values, how they work, etc.
Then…
Go to THIS webpage and bookmark it (VERY useful for this):
http://www.exploringbinary.com/binary-converter/
From there, you can enter a maskBit value (such as 2, 4, 6, etc) and see what categoryBits it will collide with (will be explained soon).
PRACTICAL EXAMPLE
Now, let’s say for example you have MONSTERS, a PLAYER, and ITEMS.
MONSTERS should collide with only players, PLAYER should collide with both MONSTERS and ITEMS, and ITEMS should collide only with the PLAYER.
MONSTERS will have the following settings:
-
categoryBits = 2
-
maskBits = 4
NOTE: maskBits of 4 will collide with categoryBits 1 and 3 (use that webpage I provided)
PLAYER will have the following settings:
-
categoryBits = 1
-
maskBits = 3
NOTE: maskBits of 3 will collide with categoryBits 1 and 2
ITEMS will have the following settings:
-
categoryBits = 2
-
maskBits = 4
NOTE: maskBits of 4 will collide with categoryBits 1 and 3.
Also note that I didn’t test the above example, but that’s the exact process I used to get collision masks working in my game.
According to the notes I provided under each one, you’ll see that MONSTERS will collide with the PLAYER (categoryBit 1), but not ITEMS (categoryBit 2). The PLAYER will collide with both monsters and items (it would also collide with other player objects, but for the sake of this example there is only 1 player). ITEMS will collide only with the PLAYER but not MONSTERS.
If you use that webpage I provided, you can see how it works a little easier. Plug in a number into the first field (it’s labeled decimal, but just put in a whole number like 6) and then click ‘Convert’. Ignore the binary field, and look to the right where it says ‘Num Digits’ and those are the ‘categoryBits’ that that particular maskBit will collide with.
So for example, type in 6 and it’ll output 1.0 to 3.0. That means the maskBit of 6 will collide with anything that has a categoryBit of 1 or 3.
From there, you should be able to figure it out based on your game’s requirements. Like I said, I didn’t test that EXACT example, but I did use the same method to get it working in my game. Please let me know if my example is flawed and I’ll work to fix it.
Hope that helps! [import]uid: 7849 topic_id: 1811 reply_id: 5494[/import]