Can somebody please explain to me setMask?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Can somebody please explain to me setMask?

Post by Kuromeku »

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.

:?
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Can somebody please explain to me setMask?

Post by rude »

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)
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Can somebody please explain to me setMask?

Post by Kuromeku »

What is mask bits and category bits?
u9_
Citizen
Posts: 54
Joined: Thu Oct 23, 2008 7:12 am

Re: Can somebody please explain to me setMask?

Post by u9_ »

The box2d documentation will have a very good explanation of this (if i remember correctly), check it out :)
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Can somebody please explain to me setMask?

Post by Kuromeku »

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

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

Re: Can somebody please explain to me setMask?

Post by surtic »

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... ;)
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

Re: Can somebody please explain to me setMask?

Post by Kuromeku »

Hmm, I think I understand a bit better, thanks.
User avatar
athanazio
Citizen
Posts: 96
Joined: Fri Apr 10, 2009 3:12 am
Location: Rio de Janeiro - Brazil
Contact:

Re: Can somebody please explain to me setMask?

Post by athanazio »

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.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Can somebody please explain to me setMask?

Post by rude »

athanazio wrote:... is very clear and should go to the documentation !!
Then please add it to the issue tracker, or I'll forget it! I'm not going to update the docs until the new documentation system [1] is in place (unless there are errors).

[1]: Yes, YET another one.
Post Reply

Who is online

Users browsing this forum: K2-XT and 134 guests