The manual says:

Sorry but I don’t get this. Does that mean if the decimal number in binary has at least one 1 or 0 and so does the other number, then the objects will be tested? How many number choices do you have then? And is there an easy way to check if a decimal number shares a bit in binary representation, compared to another number?

Seems to only answer first part of my question.
Here numbers in range 0,32:

``````0000 0000 0000 0000 0000 0000 0000 0001
0000 0000 0000 0000 0000 0000 0000 0010
0000 0000 0000 0000 0000 0000 0000 0100
0000 0000 0000 0000 0000 0000 0000 1000
0000 0000 0000 0000 0000 0000 0001 0000
0000 0000 0000 0000 0000 0000 0010 0000
0000 0000 0000 0000 0000 0000 0100 0000
0000 0000 0000 0000 0000 0000 1000 0000
0000 0000 0000 0000 0000 0001 0000 0000
0000 0000 0000 0000 0000 0010 0000 0000
0000 0000 0000 0000 0000 0100 0000 0000
0000 0000 0000 0000 0000 1000 0000 0000
0000 0000 0000 0000 0001 0000 0000 0000
0000 0000 0000 0000 0010 0000 0000 0000
0000 0000 0000 0000 0100 0000 0000 0000
0000 0000 0000 0000 1000 0000 0000 0000
0000 0000 0000 0001 0000 0000 0000 0000
0000 0000 0000 0010 0000 0000 0000 0000
0000 0000 0000 0100 0000 0000 0000 0000
0000 0000 0000 1000 0000 0000 0000 0000
0000 0000 0001 0000 0000 0000 0000 0000
0000 0000 0010 0000 0000 0000 0000 0000
0000 0000 0100 0000 0000 0000 0000 0000
0000 0000 1000 0000 0000 0000 0000 0000
0000 0001 0000 0000 0000 0000 0000 0000
0000 0010 0000 0000 0000 0000 0000 0000
0000 0100 0000 0000 0000 0000 0000 0000
0000 1000 0000 0000 0000 0000 0000 0000
0001 0000 0000 0000 0000 0000 0000 0000
0010 0000 0000 0000 0000 0000 0000 0000
0100 0000 0000 0000 0000 0000 0000 0000
1000 0000 0000 0000 0000 0000 0000 0000``````

None match.

I thought you could have some values which are not the same, but still have similar bit and so will return True.

Lets say you want your players to collide with each other, so they are both ‘from’ and ‘into’ objects for each other. And then there are NPCs which can be both ‘from’ and ‘into’ for each other, but only ‘from’ for players. And yet you want both players and NPCs to be a ‘from’ for the walls.

The quote is making a statement about the RESULT (of comparing two bitmaks: mask1 & mask2). The RESULT is only one number. No “other” number involved in this statement.

The statement is that if this RESULT is non-zero (and only then) then two objects are checked for collision.

The result is non-zero if it has at least one bit set.

Example:

``````m1       = 0000 0000 0000 0000 0000 0000 1111 0001
m2       = 0000 0000 0000 0000 0000 1111 0000 0010
m1 &  m2 = 0000 0000 0000 0000 0000 0000 0000 0000
---> value of (m1 & m2) = 0, so NO COLLISION CHECK

m1       = 0000 0000 0000 0000 0000 0000 1111 0101
m2       = 0000 0000 0000 0000 0000 1111 0000 0110
m1 &  m2 = 0000 0000 0000 0000 0000 0000 0000 0100
---> value of (m1 & m2) = 4, so DO COLLISION CHECK``````

And yes, there is an easy way to see if two numbers share a bit, it’s “number1 & number2”, duh.

Yes you can :
BitMask32(0): 0000 0000 0000 0000 0000 0000 0000 0000
BitMask32(1): 0000 0000 0000 0000 0000 0000 0000 0001
BitMask32(2): 0000 0000 0000 0000 0000 0000 0000 0010
BitMask32(3): 0000 0000 0000 0000 0000 0000 0000 0011
BitMask32(4): 0000 0000 0000 0000 0000 0000 0000 0100
BitMask32(5): 0000 0000 0000 0000 0000 0000 0000 0101
BitMask32(6): 0000 0000 0000 0000 0000 0000 0000 0110
BitMask32(7): 0000 0000 0000 0000 0000 0000 0000 0111
BitMask32(8): 0000 0000 0000 0000 0000 0000 0000 1000
BitMask32(9): 0000 0000 0000 0000 0000 0000 0000 1001
BitMask32(10): 0000 0000 0000 0000 0000 0000 0000 1010

Hm, OK this must be whats confusing me:

``````BitMask32(int)

What’s the difference?

``And yes, there is an easy way to see if two numbers share a bit, it's "number1 & number2", duh.``

Yeah, I didn’t word that very well. I mean without having to actually check if the two numbers don’t return 0 and then memorizing that. I mean is there maybe some kind of pattern? (like 1, 10, 20,… or 2, 4, 8, 16,…). Don’t want the other person reading my code to actually & all the numbers to find out what I intended to collide with what (could put that info in a comment, but if there is some pattern like above then thats a needless comment).

There is a pattern indeed, and you’re right to suggest powers of two. I use constants and the binary or to make my code more clear to the user.

Here’s an example of what I’d do.

``````COL_FLOOR = 1
COL_WALL = 2
COL_CREATURES = 4
COL_MOUSEPICK = 8 # You can click on these.

self.evil_ghost.setCollisionMask(COL_FLOOR | COL_MOUSPICK) # Ghosts never fall through the floor in movies.``````

Not the smartest example ever, but that gives the idea.

``````>>> a=BitMask32(10)
>>> print a
0000 0000 0000 0000 0000 0000 0000 1010
>>> print b
0000 0000 0000 0000 0000 0100 0000 0000``````