cocos2d running sequences in order on different targets(cocos2d 在不同目标上按顺序运行序列)
问题描述
所以,我有一个基本的游戏场景:
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 在不同目标上按顺序运行序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:cocos2d 在不同目标上按顺序运行序列
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01