Game Development Reference
In-Depth Information
Caution
It's a common mistake to set the custom class of the button itself, con-
sequently creating a subclass of
CCButton
to handle the button selectors. But-
tons are never the receivers of their own selectors.
Select the root node in
GameMenuLayer.ccb
, and switch to the
Item Code Connections
tab. In the
Custom class
field, enter
GameMenuLayer
.
Furthermore, you'll want access to the
GameMenuLayer
root node from within the
GameScene
class. Open
GameScene.ccb
, select the sub file node referencing
GameMenuLayer.ccb
, and then set
Doc root var
to
_gameMenuLayer
. This will
assign a reference to the
GameMenuLayer.ccb
root node to the
GameScene
ivar named
_gameMenuLayer
, which you'll add next.
Caution
Another common mistake is to edit the
Doc root var
field of the
GameMenuLayer.ccb
root node rather than its reference in
GameScene.ccb
. Do-
ing so will literally create a
self
reference in a
GameMenuLayer
ivar.
Changing the variable type to
Owner var
will not work either because the
owner is a reference you specify in code when using the
CCBReader
method
load:owner:
.
Programming the GameMenuLayer
It's time to fire up Xcode again to add the
GameMenuLayer
class and the
shouldPauseGame
method.
Your first goal should always be to make new code connections technically functional as
soon as possible and verify that they work. It's a potential waste of time to start writing
code without first confirming that the connected selectors actually run and the ivars or
properties are being assigned properly. You may be inclined to find the flaw in your logic
instead, possibly wasting time looking for issues in all the wrong places. It's the program-
ming equivalent for “Did you plug it in?” issues.
Implementing and Confirming Code Connections
Search WWH ::
Custom Search