Now that we have a world to live in, we need to add our hero. We have broken out our hero into a separate class, but first let's look at how we figure out where the hero will spawn. As you may recall, we have the location playerSpawn marked on the map. Now, we need to translate that location into game coordinates.
-(void) addHero { // Get the player spawn location NSMutableDictionary *playerSpawn = [spawns objectNamed:@"playerSpawn"]; NSAssert(playerSpawn != nil, @"playerSpawn missing"); int x = [[playerSpawn valueForKey:@"x"] intValue]; int y = [[playerSpawn valueForKey:@"y"] intValue]; CGPoint heroPos = ccp(x / CC_CONTENT_SCALE_FACTOR(), y / CC_CONTENT_SCALE_FACTOR()); // Create the player hero = [TDHero heroAtPos:heroPos onLayer:self]; [self addChild:hero]; }
Here you see that we create an NSMutableDictionary
from the playerSpawn
. The data is stored in this...