如何在 runAction 结束时调用特定函数?
我正在对精灵执行 runAction 以移动到某个位置。
[[crBalls[cb.count] getball] runAction:[CCSequence actions:[CCMoveTo actionWithDuration:timeToTravel position:ccp(xIntercept,yIntercept)],[CCMoveTo actionWithDuration:0.05 position:FD],nil]];
一旦精灵移动到所需的位置(FD),我想在那时调用一个函数。现在我正在安排一个选择器在“timeToTravel”延迟后调用,这是上述操作完成执行所需的时间。(我使用调度程序而不是执行选择器,因为执行选择器更容易出现问题)
[self schedule:@selector(placeThatDamnBall) interval:timeToTravel+0.05];
-(void) placeThatDamnBall
{
[self unschedule:@selector(placeThatDammBall)];
[self ballPlacedIn:FD.x :FD.y :cb.type : cb.count];
}
但这是并不完全可靠,并且在极少数情况下可能会导致问题,即该函数可能会在精灵到达目的地之前被调用。有什么方法可以避免调用选择器并能够在精灵真正到达目的地后调用该函数吗?
谢谢
I am performing a runAction on a sprite to move to a position.
[[crBalls[cb.count] getball] runAction:[CCSequence actions:[CCMoveTo actionWithDuration:timeToTravel position:ccp(xIntercept,yIntercept)],[CCMoveTo actionWithDuration:0.05 position:FD],nil]];
Once the sprite moves to the desired position(FD) then I want to call a function at that time. Right now I am scheduling a selector to be called after a delay of 'timeToTravel' which is the time taken by the above action to finish performing.(I am using scheduler instead of performSelector since perform selector is more prone to problems)
[self schedule:@selector(placeThatDamnBall) interval:timeToTravel+0.05];
-(void) placeThatDamnBall
{
[self unschedule:@selector(placeThatDammBall)];
[self ballPlacedIn:FD.x :FD.y :cb.type : cb.count];
}
But this is not entirely reliable and may cause problem in a rare case where the function might get called before the sprite reaches the destination. Is there any way I can avoid having to call a selector and be able to call the function once the sprite has truly reached the destination?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在序列末尾添加一个
CCCallFunc
:Add a
CCCallFunc
at the end of your sequence: