开发者

Making an "EnemyFactory"

开发者 https://www.devze.com 2023-02-08 02:53 出处:网络
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.

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号