Game Development Reference
In-Depth Information
Tip
To learn more about weak and strong variables, and when and why to use
them as well as general memory-management guidelines, you'll find that in-
formation in Apple's “Advanced Memory Management Programming Guide”:
tion/Cocoa/Conceptual/MemoryMgmt
, specifically the “Practical
Memory Management” section. The guide is amended by the “Transitioning to
ARC Release Notes” found here:
https://developer.apple.com/
gToARC
. Note that the topic's projects, SpriteBuilder, and Cocos2d-Swift all
use ARC (automatic reference counting) to make memory management a lot
easier.
With the preceding variables declared, you should get a reference to the player node and
assign it to
_playerNode
. The simplest way to get a node reference is by its name. To
do so, open the Level1.ccb within SpriteBuilder and select the player node. On the Item
Properties tab, enter
player
(all lowercase) into the Name text field.
Caution
Only the
Name
property of a node can be used to obtain the node by
its name. Changing the name of a node in the Timeline alone will not make it
accessible by this name. The Timeline names are only for clarity in SpriteBuild-
er.
Publish the project and go back to Xcode. In
GameScene.m
, add the code highlighted in
Listing 3-2
.
Enable user interaction
-(void) didLoadFromCCB
{
// enable receiving input events
self.userInteractionEnabled = YES;
// load the current level
[self loadLevelNamed:nil];
}
Search WWH ::
Custom Search