Skip to content

Category and Mask Bits

selimanac edited this page Oct 8, 2024 · 3 revisions

Mask bits for collision filtering work the same way as Group and Mask in Defold. They only operate within a single group.

Although categories are limited to 64 bits, I strongly recommend staying within 32 bits due to potential platform differences.

Example

Each category should be a unique power of two, ensuring clear and non-overlapping bitwise representations. More bitwise operations available on Defold API docs.

	local collision_bits = {
		PLAYER      = 1, 
		ENEMY       = 2, 
		GROUND      = 4,
		ITEM        = 8, 
		TRIGGER     = 16, 
		WALL        = 32, 
		PLATFORM    = 64, 
		PROJECTILE  = 128, 
		NPC         = 256,
		ENVIRONMENT = 512, 

		ALL         = bit.bnot(0)  -- -1 for all results
	}
	-- Mask bits to use with queries
	local mask_bits = bit.bor(collision_bits.ENEMY, collision_bits.ITEM)

Clone this wiki locally