Collision Calculator (ssk.cc.*)
The Collision Calculator allows you to quickly and easily configure single-body collisions rules using names instead of numbers.
Creating a Calculator
Creating a new myCC is as easy as:
local myCC = ssk.cc.newCalculator()
Calculator Methods (myCC:*)
addName | addNames | collidesWith |
getCategoryBits | getMaskBits | getCollisionFilter |
dump |
addName
Add new 'named' collider type to known list of collider types, and automatically assign a number to this collider type (16 Max).
myCC:addName( colliderName )
colliderName
- String containing name for new collider type.
local myCC = ssk.cc.newCalculator()
myCC:addName( "block" )
myCC:addName( "redBall" )
myCC:addName( "greenBall" )
addNames
Same as addNames, but takes multiple strings in one call.
myCC:addNames( ... )
...
- One or more strings containing name for new collider type.
local myCC = ssk.cc.newCalculator()
myCC:addNames( "block", "redBall", "greenBall" )
collidesWith
Automatically configure named collider A to collide with one or more other named colliders.
Returns true if named type was successfully added to known colliders list, false otherwise.
myCC:collidesWith( colliderNameA, ... )
colliderNameA
- A string containing the name of the collider that is being configured....
- One or more strings identifying previously added collider types that collide with colliderNameA.
local myCC = ssk.cc.newCalculator()
-- 'redBall' collides with 'block' and 'greenBall'
myCC:collidesWith( "redBall", { "block", "greenBall" } )
getCollisionFilter
Get collision filter for the named collider.
myCC:getCollisionFilter( colliderName )
colliderName
- A string containing the name of the collider you want the CollisionFilter for.
-- Create an Object with a Collision Body (Get Filter)
local tmp = display.newCircle( 100, 100, 10 )
tmp:setFillColor( 1, 0, 0 )
physics.addBody( tmp, "dynamic", { radius = 10, filter = myCC:getCollisionFilter( "redBall" ) } )
getCategoryBits
Get category bits for the named collider.
Note: Rarely used. Use the getCollisionFilter() function instead.
myCC:getCategoryBits( colliderName )
colliderName
- A string containing the name of the collider you want the CategoryBits for.
local myCC = ssk.cc.newCalculator()
myCC:getCategoryBits()
getMaskBits
Get mask bits for the named collider.
Note: Rarely used. Use the getCollisionFilter() function instead.
myCC:getMaskBits( colliderName )
colliderName
- A string containing the name of the collider you want the MaskBits for.
local myCC = ssk.cc.newCalculator()
myCC:getMaskBits()
dump
(Debug Feature) Prints collider names, numbers, category bits, and masks.
local myCC = ssk.cc.newCalculator()
myCC:addNames( "block", "redBall", "greenBall" )
myCC:collidesWith( "redBall", { "block", "greenBall" } )
myCC:dump()
Prints:
*********************************************
Dumping collision settings...
name | num | cat bits | col mask
-------------- | --- | -------- | --------
redBall | 2 | 2 | 5
block | 1 | 1 | 2
greenBall | 3 | 4 | 2
*********************************************
Copyright © Roaming Gamer, LLC. 2008-2016; All Rights Reserved