Skip to content

Instantly share code, notes, and snippets.

@kallepersson
Created June 20, 2013 07:04
Show Gist options
  • Save kallepersson/5820778 to your computer and use it in GitHub Desktop.
Save kallepersson/5820778 to your computer and use it in GitHub Desktop.
//TDGameViewController
- (void)spawnMob
{
if([self.waypoints count] > 1) {
TDMob *mob = [[TDMob alloc] initWithStartingWaypoint:[self.waypoints objectAtIndex:0]];
[mob setTargetWaypoint: [self.waypoints objectAtIndex:1]];
[self.scene addChild:mob];
}
}
//TDMob
-(void)setTargetWaypoint:(TDWaypoint *)targetWaypoint
{
float distance = DistanceBetweenTwoPoints(self.position, targetWaypoint.position);
NSTimeInterval duration = 1.0 * (distance / self.pixelsPerSecond);
SKAction *act = [SKAction moveTo:targetWaypoint.position duration:duration];
[self runAction:act completion:^{
if(targetWaypoint.nextWaypoint) {
[self setTargetWaypoint:targetWaypoint.nextWaypoint];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment