How can I make a new class that I can incorporate into my other Levels of my game that produces enemies? I'm using cocos2d btw. I would like to achieve the effect that I only have to do this.
[EnemyFactory enemy开发者_JAVA百科Type:enemy amount:15];
Thanks!
EDIT - I'm trying to make a factory of sprites, that can produce them at a given time. Please read the comments
In your enemy.h
//import library
@interface EnemyFactory : NSObject {
//blah blah blah
}
-(void)initWithEnemy:(int)type amount:(int)amt
Your enemy.m
-(id)initWithEnemy:(int)type amount:(int)amt
{
self = [super init]
if(self)
{
for(int i = 0 ; i<amt; i++)
{
switch(type){
case 1:
//blah blah blah
break;
case 2:
//blah blah blah
break;
}
}
}
return self;
}
Your game call..
EnemyFactory* factory = [[EnemyFactory alloc]initWithEnemy:enemy amount:15];
[factory release];
精彩评论