Multiple masks

Hello guys.

Is that possible to add multiple masks to group object?

Thanks

Yes, make an enum table like this: 

local bitTable = {enemyLaser = 1, screen = 2, star = 4, enemy1 = 8, shipLaser = 16, ship = 32}

and then add all of the bits for the masks you want to have:

local screenCollisionFilter = { categoryBits = bitTable.screen,maskBits = bitTable.star + bitTable.enemyLaser + bitTable.shipLaser}

Thank you for he answer, but i can’t understand how its work 

You make all of these enum values powers of two. Then when you are setting maskBits equal to the multiple masks you want to use, you add up the bits from the enum type you created. In the example above, I wanted “screen” to collide with “star” and “enemyLaser”. Since the enum type is all unique powers of two, adding the powers of 2 which correspond to “star” and “enemyLaser” create a unique integer which won’t be the same as any other combination of these enum object. This way, your code knows which objects you want in your mask.

Yes, make an enum table like this: 

local bitTable = {enemyLaser = 1, screen = 2, star = 4, enemy1 = 8, shipLaser = 16, ship = 32}

and then add all of the bits for the masks you want to have:

local screenCollisionFilter = { categoryBits = bitTable.screen,maskBits = bitTable.star + bitTable.enemyLaser + bitTable.shipLaser}

Thank you for he answer, but i can’t understand how its work 

You make all of these enum values powers of two. Then when you are setting maskBits equal to the multiple masks you want to use, you add up the bits from the enum type you created. In the example above, I wanted “screen” to collide with “star” and “enemyLaser”. Since the enum type is all unique powers of two, adding the powers of 2 which correspond to “star” and “enemyLaser” create a unique integer which won’t be the same as any other combination of these enum object. This way, your code knows which objects you want in your mask.