Game Development Reference
In-Depth Information
Listing 5-15. Example02Controller.m (addActor: and removeActor:)
-(void)removeActor:(Actor02*)actor{
[toBeRemoved addObject:actor];
}
-(void)doRemove{
for (Actor02* actor in toBeRemoved){
UIImageView* imageView=[actorViews objectForKey:[actor actorId]];
[actorViews removeObjectForKey:actor];
[imageView removeFromSuperview];
[actors removeObject:actor];
}
[toBeRemoved removeAllObjects];
addActor simply adds the actor to the NSMutableArray actors . If you
removeActor simply adds the actor to the NSMutableArray toBeRemoved , so it can be
doRemove finds the UIImageView used to draw it on the screen and
UIView actorViews . The UIImageView is also removed from the scene by calling
. The object actor is also removed from the NSMutableArray actors . Now that
updateScene
Listing 5-16. Example02Controller.m (updateScene)
-(void)updateScene{
if (stepNumber % (60*10) == 0){
[self addActor:[Asteroid02 asteroid:self]];
}
for (Actor02* actor in actors){
[actor step:self];
}
for (Actor02* actor in actors){
if ([actor isKindOfClass:[Asteroid02 class]]){
if ([viper overlapsWith:actor]){
[viper doCollision:actor In:self];
break;
}
}
}
for (Actor02* actor in actors){
[self updateActorView:actor];
}
[self doRemove];
stepNumber++;
}
Search WWH ::




Custom Search