gpt4 book ai didi

iOS7 Sprite Kit如何设置一系列依赖动画时序的 Action ?

转载 作者:行者123 更新时间:2023-11-29 12:57:17 24 4
gpt4 key购买 nike

澄清一下:这不是关于序列或 SKAction 组的问题。

我在 2D 游戏板上有 7-20 个代表怪物的 Sprite 。我希望他们一个接一个地表演。 Action 可以是移动,也可以是移动和攻击。

我遇到的问题是前几个怪物似乎行动正常, - 一个怪物移动,攻击,然后是下一个,等等。但是在他们中的一些之后( 4-5) 序列中断,多个怪物同时开始行动

这是我下面的递归移动/AI 方法的问题,还是 Sprite Kit 中的某些东西干扰了序列?

我看到 xCode 中的调用堆栈似乎在增长,并且我看到对 processMonsterAI 的多次调用,但这不是每个怪物调用 1 次的情况。

我特别感兴趣是否应该使用 NSTimers 或延迟调度队列 block 而不是依赖 Sprite Kit 的完成 block ?

每一回合,我的 AI 都必须移动棋盘上的怪物:

-(void)processMonsterAI
{
CharacterModelNode* monster = [allMonstersCopy lastObject];
[allMonstersCopy removeLastObject];

AIBase* ai = monster.character.AI;
ai.delegate = self;
ai doAIAction];

}

AI 经常做出在棋盘上移动的决定,动画显示为从一个单元格移动到下一个单元格,一步一步,直到怪物停止移动或到达目的地:

//do recursive movement animation

-(void)recursiveMoveWithCharacter:(CharacterModelNode*)characterModel path:(NSMutableArray*)path
{
//check if we ran out of moves
if(path.count == 0)
{
//notify delegate
[self moveCompleteForCharacter:characterModel];

}else
{
NSNumber* tileIndex = path[0];
CGPoint destination = [MapOfTiles positionForTileAtIndex:tileIndex.intValue];
[path removeObjectAtIndex:0];

[self runAction:[SKAction moveTo:destination duration:1]
completion:^{

characterModel.character.currentMoves = characterModel.character.currentMoves-1;

[self recursiveMoveWithCharacter:characterModel path:path];
}];

}
}

动画完成后,会通知 AI 怪物处于正确位置,然后可以执行攻击序列:

//once animation is complete, call
-(void)moveComplete
{

if(self.bestTarget)
{
[self.actor attack:self.bestTarget];
}
//notify whoever is the delegate that we are done here and the next AI can do it's magic.

[self finishAction];
}


//AI is done, notify delegate to process next monster
-(void)finishAction
{
NSLog(@"Finished :%@",self.actor.character.name);
[self.actor debugFlashRed];
if([self.delegate respondsToSelector:@selector(didFinishAIAction:)])
{
[self.delegate didFinishAIAction:self];
}
}

继续移动/攻击下一个怪物

//either repeat the process, or terminate if all monsters acted
-(void)didFinishAIAction:(AIBase*)AI
{
if(allMonstersCopy.count==0)
{
//finished with monster turn
[self preventUserInteraction:NO];
[[GameDataManager sharedInstance] processEndTurn];

}else
{
[self processMonsterAI];
}
}

更新:

这是调用堆栈,它命中了某些 AI 不止一次调用 finishAction 的断言: enter image description here

最佳答案

doAIAction 是否可能经过多条路径,可能会多次调用 finishAction?这似乎是一种可能性。您显示的代码中实际上没有任何分支会导致多个 processMonsterAI 调用。

关于iOS7 Sprite Kit如何设置一系列依赖动画时序的 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20750413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com