Game Development Reference
In-Depth Information
ively. For now, it's only noteworthy that loadAsScene: returns a plain CCScene in-
stance with the GameScene.ccb root node as its only child. I'll explain this in more detail
soon.
Publish again, and run the app. It'll bring up the GameScene with the button, but tapping
the button doesn't do anything useful yet.
Creating a Custom Class for the GameScene
For code connections to work, both when specifying a selector and when assigning a node
as an ivar (short for “instance variable of a class”), you will have to specify a custom class
in SpriteBuilder. Then create the class of the same name containing the corresponding se-
lector/ivar in Xcode. Or vice versa; the order is not important.
Both for selectors and ivars, you can specify a target, which defaults to Document root
and Doc root var , respectively. This so-called “document root” refers to the root node of
the CCB file which contains the currently edited node. The root node is the topmost node
in the hierarchy—the one that's already there when you create a CCB file. (See Figure
2-8 . ) Therefore, the custom class property must be edited on the root node.
Figure 2-8 . The root node is selected
Note Using the Owner setting as the target for selectors and ivars is done only
in cases where you load the contents of a CCB at runtime with an already exist-
ing scene. You can specify a custom object (owner) as the receiver of selectors
and ivars. One use for this is to map an overlay-menu CCB's button selectors to
the scene's original custom class. A common misconception is that the Owner
setting refers to the custom class of the selected node—that is not the case.
Select the root node in the GameScene.ccb, and switch to the Code Connections tab on the
Detail View. The root node is always the first node in the node hierarchy. You can most
easily select it in the Timeline View, as seen in Figure 2-8 .
Search WWH ::




Custom Search