问题描述
所以,我有一个基本的游戏场景:
So, i have a basic game scenerario:
一些单位靠近敌方单位,发射弹丸,然后调整敌方单位的生命.我的问题是我不确定如何安排这三个事件一个接一个地运行.如果所有这些操作都在同一个目标上完成,那么这将非常容易,但是有两个不同的目标.
Some unit moves close to an enemy unit, shoots projectile and then enemy unit's life is adjusted. My problem is that I am not sure how to schedule these three events to run one after another. If all these actions were done on the same target, then this would be super easy, but there are two different targets.
最好的方法是什么?
代码如下:
Unit* unit = [self getActiveUnit];
Unit* enemy = [self getEnemyInRange:unit];
CGpoint A = unit.sprite.position;
CGPoint B = [self getPositionClose:enemy for:unit];
CCSequence* unitMove = [self generateUnitMoveFrom:A to:B];
Projectile* proj = [self generateProjectile];
CCSequence* projMove = [self generateProjMoveFrom:A to:B];
CCSequence* attackDone = [self generateAttackDoneFor:unit enemy:enemy];
// This is the part that i don't know how to do
// Execute these in order and sequentially, not at the same time
[unit.sprite runAction:unitMove];
[proj.sprite runAction:projMove];
[proj.sprite runAction:removeSprite];
[self runAction:attackDone];
执行此操作的最佳方法是什么?即使使用 CCActionManager 它似乎仍然相当复杂,因为我认为我必须在所有这些操作之间添加一个额外的回调才能恢复下一个目标的预定操作.
What is the best approach to do this? Even using CCActionManager it still seems fairly complicated because i think i would have to add an extra call back between all these actions to resume scheduled actions for the next target.
有什么想法吗?
谢谢!
推荐答案
我会尝试使用 CCSequence
[self runAction:[CCSequence actions:
[CCCallFuncO actionWithTarget:unit.sprite selector:@selector(runAction:) object:unitMove],
[CCCallFuncO actionWithTarget:proj.sprite selector:@selector(runAction:) object:projMove],
[CCCallFuncO actionWithTarget:proj.sprite selector:@selector(runAction:) object:removeSprite],
[CCCallFunc actionWithTarget:self selector:@selector(attackDone)],
nil]];
这篇关于cocos2d 在不同目标上按顺序运行序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!