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 在不同目标上按顺序运行序列
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01