CollisionGroup
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
STOP!!** It is preferred that [[CollisionGroupManager.create]] is used to create collision groups unless you know how to construct the proper bitmasks. See https://github.com/excaliburjs/Excalibur/issues/1091 for more info.
Parameters
name: string
Name of the collision group
category: number
32 bit category for the group, should be a unique power of 2. For example
0b001
or0b010
mask: number
32 bit mask of category, or
~category
generally. For a category of0b001
, the mask would be0b110
Returns CollisionGroup
Properties
publicstaticAll
The All
[[CollisionGroup]] is a special group that collides with all other groups including itself,
it is the default collision group on colliders.
Accessors
publiccategory
Get the category of the collision group, a 32 bit number which should be a unique power of 2
Returns number
publicmask
Get the mask for this collision group
Returns number
publicname
Get the name of the collision group
Returns string
Methods
publiccanCollide
Evaluates whether 2 collision groups can collide
This means the mask has the same bit set the other category and vice versa
Parameters
other: CollisionGroup
CollisionGroup
Returns boolean
publicinvert
Inverts the collision group. For example, if before the group specified "players", inverting would specify all groups except players
Returns CollisionGroup
CollisionGroup
publictoString
Returns string
publicstaticcollidesWith
Creates a collision group that collides with the listed groups
Parameters
collisionGroups: CollisionGroup[]
Returns CollisionGroup
publicstaticcombine
Combine collision groups with each other. The new group includes all of the previous groups.
Parameters
collisionGroups: CollisionGroup[]
Returns CollisionGroup
CollisionGroups indicate like members that do not collide with each other. Use [[CollisionGroupManager]] to create [[CollisionGroup]]s
For example:
Players have collision group "player"
Enemies have collision group "enemy"
Blocks have collision group "ground"
Players don't collide with each other, but enemies and blocks. Likewise, enemies don't collide with each other but collide with players and blocks.
This is done with bitmasking, see the following pseudo-code
PlayerGroup =
0b001
PlayerGroupMask =0b110
EnemyGroup =
0b010
EnemyGroupMask =0b101
BlockGroup =
0b100
BlockGroupMask =0b011
Should Players collide? No because the bitwise mask evaluates to 0
(player1.group & player2.mask) === 0
(0b001 & 0b110) === 0
Should Players and Enemies collide? Yes because the bitwise mask is non-zero
(player1.group & enemy1.mask) === 1
(0b001 & 0b101) === 1
Should Players and Blocks collide? Yes because the bitwise mask is non-zero
(player1.group & blocks1.mask) === 1
(0b001 & 0b011) === 1