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 在不同目标上按顺序运行序列
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
