Game Development Reference
In-Depth Information
Timeline. Then rename this node to
triggers
. This will be the container for all the trigger
nodes.
Now you can drag a
TriggerOnce
from the
Tileless Editor View
onto the
triggers
node in the Timeline. Change the trigger's
Name
property on the
Item
Properties
tab to
triggerSawRotation
. The name connects the trigger with nodes of
the same nameāthe saw nodes you've added earlier also have
triggerSawRotation
as
their name. The target nodes will receive a message when the player (or other nodes)
cause the trigger to activate.
Change the trigger's position, and use the selection handles to resize (scale) the object to
best match the desired size of the trigger area. Just make sure the player will be able to
collide with it.
You can also create copies of this new trigger if you want to form a more complex trigger
shape. Multiple triggers can overlap without issues.
Creating the Trigger Class
If you were to build and run the Xcode project now, you would receive an error originat-
ing from
CCBReader
that states that the custom class
Trigger
cannot be found. You
may want to try and run the project just to get acquainted with the error message, as you'll
probably encounter it from time to time.
To fix this error, you'll need to add a class of the same name as you've entered under the
Item Code Connections
tab in the
Custom class
field of the trigger's color
node. That class' name is
Trigger
, in case this wasn't obvious.
In Xcode, select the
Project Navigator
tab. That's the leftmost tab where the files,
groups (yellow folder icons), and folders (blue folder icons) are shown in a hierarchical
view not unlike Finder displays files and folders. Right-click the
Source
group and se-
Touch section, select Objective-C class, and then click
Next
, which will show the dialog
you see in
Figure 2-10
. Enter
Trigger
in the Class field, and make it a
Subclass of
CCNode
before clicking
Next
. You'll end up with two new files in the Xcode project,
named
Trigger.h
and
Trigger.m
.
Again, try to run the project, and once more you'll receive an error message regarding a
missing property named
triggerCount
. The
Trigger
class is still missing this prop-
erty or ivar.
Search WWH ::
Custom Search