Placing defenses
Once the predefined positions have been loaded, let's add the defenses.
This will happen when the player touches the screen at one of the available positions, so add the following import at the top of GameScene.h
:
#import "Defense.h"
Then in GameScene.m
, declare an array of defenses:
// Declare array of defenses NSMutableArray *_defenses;
Initialize it by adding the following lines at the end of the init
method:
// Initialize array of defenses _defenses = [[NSMutableArray alloc] initWithCapacity:kNUM_DEFENSES]; // Enable touches management self.userInteractionEnabled = TRUE;
We are also enabling touch handling, so we can detect when the player is touching the screen.
Finally, let's implement the touchBegan
method by adding the following lines:
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event { // Get touch position CGPoint touchLocation = [touch locationInNode:self]; // Iterate defense positions for (CCSprite *defensePosition...