Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在一个无休止的循环中一次添加一个敌人到屏幕上,每个敌人之间都有延迟,但这不起作用_Objective C_Loops_Cocos2d Iphone_Side Scroller - Fatal编程技术网

Objective c 在一个无休止的循环中一次添加一个敌人到屏幕上,每个敌人之间都有延迟,但这不起作用

Objective c 在一个无休止的循环中一次添加一个敌人到屏幕上,每个敌人之间都有延迟,但这不起作用,objective-c,loops,cocos2d-iphone,side-scroller,Objective C,Loops,Cocos2d Iphone,Side Scroller,您好,我正在制作一个侧面滚动cocos2d游戏,在这个游戏中,敌人会以一个无休止的循环一次添加到屏幕上。我想知道如何在每个增加的敌人之间设置延迟。另外,当添加“blueknoyer”时,屏幕上会出现第二个,而此时只应添加一个 以下是我目前的代码: #import "FlyingEnemy.h" @implementation FlyingEnemy +(id)createEnemies{ return [[[self alloc]init]autorelease]; } -(id)init{

您好,我正在制作一个侧面滚动cocos2d游戏,在这个游戏中,敌人会以一个无休止的循环一次添加到屏幕上。我想知道如何在每个增加的敌人之间设置延迟。另外,当添加“blueknoyer”时,屏幕上会出现第二个,而此时只应添加一个

以下是我目前的代码:

#import "FlyingEnemy.h"

@implementation FlyingEnemy
+(id)createEnemies{
return [[[self alloc]init]autorelease];
}

-(id)init{
if((self = [super init])){
    CGSize size = [[CCDirector sharedDirector]winSize];
    screenWidth = size.width;
    screenHeight = size.height;

    screenBounds = [[UIScreen mainScreen] bounds];

    redEnemyFlameCounter = 1;

    randomNumberSpinningRockRepeat = arc4random() % 4;

    xPoint = screenWidth - 50;
    yPoint = screenHeight - 50;

    yellowEnemyFlameCounter = 1;

    blueEnemyFlameCounter = 1;

    xPointBlueEnemy = screenWidth - 50;
    yPointBlueEnemy = screenHeight - 50;

    [self redEnemyFlight];
}
    return self;
}  

-(void)redEnemyFlight{
[self unschedule:@selector(redEnemyStart:)];

redEnemy = [CCSprite spriteWithFile:@"redenemy.png"];
redEnemy.position = ccp(xPoint, yPoint);
[self addChild:redEnemy z:-1];

[self schedule:@selector(shootTheBullets:)interval:1.0f/2.0f];

CCMoveTo* redEnemyMoveDown  = [CCMoveTo actionWithDuration:3.0 position:ccp(xPoint, 70)];
CCMoveTo* redEnemyMoveUp = [CCMoveTo actionWithDuration:3.0 position:ccp(xPoint, yPoint - 60)];
CCSequence* redEnemyFloatingSequence = [CCSequence actions:redEnemyMoveDown, redEnemyMoveUp, nil];
CCRepeat* redEnemyFloatingRepeat = [CCRepeat actionWithAction:redEnemyFloatingSequence times:3];
[redEnemy runAction:redEnemyFloatingRepeat];

[self schedule: @selector(removeTheEnemy:)interval:18.0f/1.0f];

[self schedule: @selector(redEnemyFlame:)interval:1.0f/5.0f];
}

-(void)redEnemyFlame:(ccTime)delta{
redEnemyFlameCounter ++;

if (redEnemyFlameCounter % 2){
    [redEnemy setTexture:[[CCSprite spriteWithFile:@"redenemy2.png"]texture]];
}else{
    [redEnemy setTexture:[[CCSprite spriteWithFile:@"redenemy.png"]texture]];
}
}

-(void)removeTheEnemy:(ccTime)delta{
CCMoveBy* moveUp = [CCMoveBy actionWithDuration:0.5 position:ccp(70, 100)];
[redEnemy runAction:moveUp];
[self unschedule:@selector(removeTheEnemy:)];

[self schedule:@selector(yellowEnemyStart:)interval:1.0f/60.0f];
}

-(void)yellowEnemyStart:(ccTime)delta{
if (redEnemy.position.x > screenWidth || redEnemy.position.y > screenHeight) {
    [self yellowEnemyFloating];
}
}

-(void)yellowEnemyFloating{
[self unschedule:@selector(yellowEnemyStart:)];

yellowEnemy = [CCSprite spriteWithFile:@"yellowenemy.png"];
yellowEnemy.position = ccp(screenWidth - 50, 50);
[self addChild:yellowEnemy z:-1];

yellowEnemyMoveDown  = [CCMoveTo actionWithDuration:2.0 position:ccp(yellowEnemy.position.x, 50)];
yellowEnemyMoveUp = [CCMoveTo actionWithDuration:2.0 position:ccp(yellowEnemy.position.x, screenHeight/2)];
yellowEnemyFloatingSequnece = [CCSequence actions:yellowEnemyMoveUp, yellowEnemyMoveDown, nil];
yellowEnemyFloatingRepeat = [CCRepeat actionWithAction:yellowEnemyFloatingSequnece times:2];
[yellowEnemy runAction:yellowEnemyFloatingRepeat];

[self schedule: @selector(yellowEnemyFlame:)interval:1.0f/5.0f];
}

-(void)yellowEnemyFlame:(ccTime)delta{
yellowEnemyFlameCounter ++;

if (yellowEnemyFlameCounter % 2){
    [yellowEnemy setTexture:[[CCSprite spriteWithFile:@"yellowenemy2.png"]texture]];
}else{
    [yellowEnemy setTexture:[[CCSprite spriteWithFile:@"yellowenemy.png"]texture]];
}
[self schedule:@selector(yellowEnemyFlight:)interval:8.0f/1.0f];

}

-(void)yellowEnemyFlight:(ccTime)delta{
yellowEnemyMoveLeft = [CCMoveTo actionWithDuration:4.0 position:ccp(-100, screenHeight/2)];
[yellowEnemy runAction:yellowEnemyMoveLeft];

[self schedule:@selector(removeTheYellowEnemy:)interval:4.0f/1.0f];
}

-(void)removeTheYellowEnemy:(ccTime)delta{
CCMoveTo* removeYellowEnemy = [CCMoveTo actionWithDuration:1.0 position:ccp(-100, screenHeight/2)];
[yellowEnemy runAction:removeYellowEnemy];
[self unschedule:@selector(removeTheYellowEnemy:)];

[self schedule:@selector(blueEnemyStart:)interval:1.0f/60.0f];
}

-(void)blueEnemyStart:(ccTime)delta{
if (yellowEnemy.position.x < 0 || yellowEnemy.position.y < 0) {
    if (redEnemy.position.x > screenWidth || redEnemy.position.y > screenHeight) {
        [self blueEnemyFlight];
    }
}
}

-(void)blueEnemyFlight{
[self unschedule:@selector(blueEnemyStart:)];

blueEnemy = [CCSprite spriteWithFile:@"blueenemy.png"];
blueEnemy.position = ccp(xPointBlueEnemy, yPointBlueEnemy);
[self addChild:blueEnemy z:-1];

[self schedule:@selector(shootTheWaterBullets:)interval:1.0f/2.0f];

CCMoveTo* blueEnemyMoveDown  = [CCMoveTo actionWithDuration:3.0 position:ccp(xPointBlueEnemy, 70)];
CCMoveTo* blueEnemyMoveUp = [CCMoveTo actionWithDuration:3.0 position:ccp(xPointBlueEnemy, yPointBlueEnemy - 60)];
CCSequence* blueEnemyFloatingSequence = [CCSequence actions:blueEnemyMoveDown, blueEnemyMoveUp, nil];
CCRepeat* blueEnemyFloatingRepeat = [CCRepeat actionWithAction:blueEnemyFloatingSequence times:3];
[blueEnemy runAction:blueEnemyFloatingRepeat];

[self schedule: @selector(removeTheBlueEnemy:)interval:18.0f/1.0f];

[self schedule: @selector(blueEnemyFlame:)interval:1.0f/5.0f];
}

-(void)blueEnemyFlame:(ccTime)delta{
blueEnemyFlameCounter ++;

if (blueEnemyFlameCounter % 2){
    [blueEnemy setTexture:[[CCSprite spriteWithFile:@"blueenemy2.png"]texture]];
}else{
    [blueEnemy setTexture:[[CCSprite spriteWithFile:@"blueenemy.png"]texture]];
}
}

-(void)removeTheBlueEnemy:(ccTime)delta{
CCMoveBy* moveUpBlueEnemy = [CCMoveBy actionWithDuration:0.5 position:ccp(200, 400)];
[blueEnemy runAction:moveUpBlueEnemy];
[self unschedule:@selector(removeTheBlueEnemy:)];

[self performSelector:@selector(redEnemyStart:)];
}

-(void)redEnemyStart:(ccTime)delta{
if (blueEnemy.position.x > screenWidth || blueEnemy.position.y > screenHeight) {
    [self redEnemyFlight];
}
}
@end
#导入“flyingemy.h”
@实现flyingemy
+(id)创建敌人{
返回[[[self alloc]init]autorelease];
}
-(id)init{
if((self=[super init])){
CGSize size=[[CCDirector sharedDirector]winSize];
屏幕宽度=size.width;
屏幕高度=size.height;
屏幕边界=[[UIScreen mainScreen]边界];
redEnemyFlameCounter=1;
randomNumberSpinningRockRepeat=arc4random()%4;
xPoint=屏幕宽度-50;
yPoint=屏幕高度-50;
黄色火焰计数器=1;
blueEnemyFlameCounter=1;
xpointbluedeny=屏幕宽度-50;
YPOINTBLUENEBY=屏幕高度-50;
[自我复仇之光];
}
回归自我;
}  
-(无效)重新点火{
[自我计划外:@selector(redEnemyStart:)];
redEnemy=[CCSprite spriteWithFile:@“redEnemy.png”];
redEnemy.position=ccp(xPoint,yPoint);
[self-addChild:redEnemy z:-1];
[自我计划:@selector(shootthebollets:)间隔:1.0f/2.0f];
CCMoveTo*redenemmovedown=[CCMoveTo-actionWithDuration:3.0位置:ccp(xPoint,70)];
CCMoveTo*redEnemyMoveUp=[CCMoveTo-actionWithDuration:3.0位置:ccp(xPoint,yPoint-60)];
CCSequence*redEnemyFloatingSequence=[CCSequence操作:redEnemyMoveDown、redEnemyMoveUp、nil];
CCRepeat*redEnemyFloatingRepeat=[CCRepeat actionWithAction:redEnemyFloatingSequence times:3];
[重新定义运行操作:重新定义浮动重复];
[自调度:@selector(removeTheEnemy:)间隔:18.0f/1.0f];
[自调度:@selector(redEnemyFlame:)间隔:1.0f/5.0f];
}
-(void)redEnemyFlame:(ccTime)delta{
redEnemyFlameCounter++;
如果(重新定义计数器%2){
[redEnemy setTexture:[[CCSprite spriteWithFile:@“redenemy2.png”]texture];
}否则{
[redEnemy setTexture:[[CCSprite spriteWithFile:@“redEnemy.png”]texture];
}
}
-(无效)删除敌人:(ccTime)增量{
CCMoveBy*moveUp=[CCMoveBy action with duration:0.5位置:ccp(70100)];
[重新定义运行动作:向上移动];
[自我计划外:@selector(removeTheEnemy:)];
[自计划:@选择器(YellowEneyStart:)间隔:1.0f/60.0f];
}
-(无效)YellowEneyStart:(ccTime)delta{
if(redEnemy.position.x>屏幕宽度| | redEnemy.position.y>屏幕高度){
[自浮];
}
}
-(无效)黄绿色{
[自我计划外:@selector(yellowEnemyStart:)];
黄色敌人=[CCSprite spriteWithFile:@“yellowDebuy.png”];
黄色敌人位置=ccp(屏幕宽度-50,50);
[self-addChild:z:-1];
yellowEnemyMoveDown=[CCMoveToActionwithDuration:2.0位置:ccp(yellowEnemy.position.x,50)];
YellowEneyMoveUp=[CCMoveToActionwithDuration:2.0位置:ccp(yellowEneyTo.position.x,屏幕高度/2)];
YellowEneyFloatingSequence=[CCSequence actions:YellowEneyMoveUp,YellowEneyMoveDown,nil];
yellowEnemyFloatingRepeat=[CCRepeat actionWithAction:YellowEneMyFloatingSequence times:2];
[YellowEneyFloatingRepeat];
[自我计划:@选择器(yellowEnemyFlame:)间隔:1.0f/5.0f];
}
-(空白)黄色火焰:(ccTime)三角洲{
yellowEnemyFlameCounter++;
如果(黄色火焰计数器%2){
[YellowEney2.png]纹理:[[CCSprite spriteWithFile:@“yellowEney2.png”]纹理];
}否则{
[YellowDebuy设置纹理:[[CCSprite spriteWithFile:@“yellowDebuy.png”]纹理];
}
[自我计划:@选择器(YellowEneyFlight:)间隔:8.0f/1.0f];
}
-(无效)yellowEnemyFlight:(ccTime)delta{
YellowEneyMoveLeft=[CCMoveToActionwithDuration:4.0位置:ccp(-100,屏幕高度/2)];
[YellowEneyMoveLeft];
[自调度:@选择器(移除黄色敌人:)间隔:4.0f/1.0f];
}
-(无效)移除黄色敌人:(ccTime)三角洲{
CCMoveTo*移除黄色敌人=[CCMoveTo行动持续时间:1.0位置:ccp(-100,屏幕高度/2)];
[黄色敌人行动:移除黄色敌人];
[自我计划外:@selector(移除黄色敌人:)];
[自调度:@selector(blueEnemyStart:)间隔:1.0f/60.0f];
}
-(无效)blueEnemyStart:(ccTime)delta{
如果(黄色敌人位置.x<0 | |黄色敌人位置.y<0){
if(redEnemy.position.x>屏幕宽度| | redEnemy.position.y>屏幕高度){
[自行飞行];
}
}
}
-(无效)blueEnemyFlight{
[自我计划外:@selector(blueEnemyStart:)];
蓝色敌人=[CCSprite spriteWithFile:@“blue敌军.png]”;
blue敌方.position=ccp(xpointblue敌方,ypointblue敌方);
[self-addChild:Blue敌手z:-1];
[自调度:@选择器(射击水桶:)间隔:1.0f/2.0f];
CCMoveTo*bluenemymovedown=[CCMoveTo actionWithDuration:3.0位置:ccp(xpointblueneyforeign,70)];
CCMoveTo*bluenemymoveup=[CCMoveTo action with duration:3.0位置:ccp(xpointblue敌方,ypointblue敌方-60)];
CCSequence*blueEnemyFloatingSequence=[CCSequence操作:blueEnemyMoveDown,blueEnemyMoveUp,nil];
CCRepeat*blueEnemyFloatingRepeat=[CCRepeat actionWithAction:blueEnemyFloatingSequence times:3];
[蓝敌runAction:blueEnemyFloatingRepeat];
[自调度:@selector(removetheblueknower:)间隔:18.0f/1.0f];
[自调度:@选择器(blueEnemyFlame:)间隔:1.0f/5.0f];
}
-(无效)blueEnemyFlame:(ccTime)delta{
blueEnemyFlameCounter++;
如果(blueEnemyFlameCounter%2){
[BlueDebuy setTexture:[[CCSprite spriteWithFile:@“blueneMy2.png”]纹理]];
}否则{
[蓝敌设置纹理:[[CCSprite spriteWithFile:@“blue敌方.png”]纹理];
}
}
-(无效)移除蓝敌:(ccTime)三角洲{
CCMoveBy*MOVEUPBLUEFOUNY=[CCMoveBy行动持续时间:0.5位置:ccp(200400)];
[蓝敌行动:向上移动蓝敌];
[自我计划外:@selector(removetheblueknower:)];
[自执行选择器:@selector(redEnemyStart:)];
}
-(无效)重新复仇星:(ccTime)三角洲{
if(blue敌方.position.x>屏幕宽度| | blue敌方.position.y>屏幕高度){
[自我复仇之光];
CCDelayTime *delay = [CCDelayTime actionWithDuration:kDelayTime];
CCCallFunc *spawnEnemy = [CCCallFunc actionWithTarget:self selector:@selector(myFoeGeneratorSelector)];
CCRepeatForever *forever = [CCRepeatForever actionWithAction:[CCSequence actionOne:delay two:spawnEnemy]];
[self runAction:forever];
[self runAction:[CCSequence actionOne:delay two:spawnEnemy]];