Game Development Reference
In-Depth Information
We need to redefine its
init
method so that we always get the same character for the
player. Add the following code to
ERGPlayer.m
:
-(instancetype)init
{
self = [super initWithImageNamed:@"character.png"];
{
self.name = playerName;
}
return self;
}
This method calls the parent implementation of the designated initializer.
Next, add the player object to
ERGMyScene.m
by adding this code to the
scene
init
method:
ERGPlayer *player = [[ERGPlayer alloc] init];
player.position = CGPointMake(100, 68);
[self addChild:player];
If you run the project now, you will see the moving background and character sprite
on it, as shown in the following screenshot:
Background and character sprites on screen