Game Development Reference
In-Depth Information
On the
Item Physics
tab for the color node, check
Enable physics
, change the
type to
Static
, and as the
Collision type
enter
trigger
. This will allow you to
handle collisions with triggers separately.
Categories
and
Masks
can be left
empty—currently, there aren't any other dynamic objects that might activate triggers be-
sides the player.
On the
Item Code Connections
tab for the color node, enter
Trigger
as the
Cus-
tom class
name. This will create an instance of the (soon to be added)
Trigger
class
for every
TriggerOnce.ccb
added to the level.
Since this particular trigger should trigger only once, switch to the
Item Properties
tab once more. At the bottom, click the
Edit Custom Properties
button and add a
custom property named
triggerCount
of type
Int
with value 1. This will make the trig-
ger activate only once before removing itself. If you omit adding this property or set it to
0, it will create a
Trigger
instance that triggers every time the player enters it. Values
greater than 1 will make the trigger activate the given number of times before removing it-
self from the level.
Tip
Feel free to add another trigger CCB in the same way, name it
Trigger-
Forever.ccb
, and omit the
triggerCount
parameter or set its value to 0.
I'm sure you will find a use for a repeatedly activatable trigger area eventually.
Note that it's also possible to create triggers with polygon shapes as opposed to purely
rectangular shapes. However, a polygon shape will not be reflected visually in
SpriteBuilder because the color node fills a rectangular area. You would have to use a
sprite node with a corresponding trigger image if you wanted to visually display a poly-
gon trigger area in SpriteBuilder.
On the other hand, you can almost always model more complex trigger areas with mul-
tiple rectangular triggers. Trigger collision areas also rarely need to be very precise either.
So it's best to avoid using polygon-shaped triggers altogether and instead combine mul-
tiple rectangular trigger areas.
Adding Triggers to the Level
Before you add any triggers to
Level1.ccb
, you should first drag another plain
Node
from the
Node Library View
onto the
CCPhysicsNode
in the
Level1.ccb
Search WWH ::
Custom Search