Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

I don't understand at all? Is it bit-wise and shit, I'm not too keen on that. Same for setCategory, setCategoryBits and setMaskBits.

rude
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Code: Select all

shape1:setCategory(1)
shape2:setCategory(2)

shape3:setMask(1) -- Does not collide with shape1
shape4:setMask(1, 2) -- Does not collide with shape1 nor shape2 (does collide with shape3)


Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

What is mask bits and category bits?

u9_
Citizen
Posts: 54
Joined: Thu Oct 23, 2008 7:12 am

The box2d documentation will have a very good explanation of this (if i remember correctly), check it out

Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

It doesn't, that's why I'm asking here.

surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

I think the explanation is that a category can be a number between 0 and 15 (i.e. 16 categories).
So when you want to specify a list of categories, you can either list them:

Code: Select all

shape:setCategory(1,3,10)
Or you can use a single number to represent this list. To do that, you calculate the sum of 2^category and use the result.
In this case: bits = 2^1+2^3+2^10 = 2+8+1024 = 1034. Then you use the "bits" function:

Code: Select all

shape:setCategoryBits(1034)
Why "bits"? Because when you look at 1034 as bits (in binary notation), you get 0000010000001010. You have '1' for the categories the shape belongs to, and '0' for the categories it doesn't belong to. And the same can be used for the mask (i.e. categories the shape can collide with).

So the short answer is, yes, it's bit-wise and shit...

Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Hmm, I think I understand a bit better, thanks.

athanazio
Citizen
Posts: 96
Joined: Fri Apr 10, 2009 3:12 am
Location: Rio de Janeiro - Brazil
Contact:

rude,
I believe the comment you did
shape1:setCategory(1)
shape2:setCategory(2)

shape3:setMask(1) -- Does not collide with shape1
shape4:setMask(1, 2) -- Does not collide with shape1 nor shape2 (does collide with shape3)
is very clear and should go to the documentation !!
Nothing is simple but everything is possible.

rude
Posts: 1051
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway