如何将多个对象传递到延迟方法? [英] How can I pass multiple objects to a delayed method?

查看:117
本文介绍了如何将多个对象传递到延迟方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何传递

- (void)explosionFromPoint:(CGPoint)explosionSprite:(CCSprite *)sprite;

[self performSelector:@selector在这里)withObject:nil afterDelay:3];

您不能将整个选择器放在 @selector() withObject 首先只允许一个对象被传递,也不知道如何使用它。

You cant put the whole selector inside the @selector(), and withObjectfirst of all only allows one object to be passed over, and neither do I understand how to use it.

如何在延迟后传递带有对象的方法?
我也尝试了一个解决方法,其中我调用

How can I pass a method with objects after a delay? I also tried a workaround where I call

[self performSelector:@selector(waitExplosion)withObject:nil afterDelay:3];
然后运行操作本身, [self explosionFromPoint:c0TileCoord withSprite:bomb];
,但这是一个非常糟糕的方法,因为我必须重新声明的变量,它只是坏。

[self performSelector:@selector(waitExplosion) withObject:nil afterDelay:3]; which then runs the action itself, [self explosionFromPoint:c0TileCoord withSprite:bomb]; , but this is a really bad way to do it as I have to re-declare the variables and it's just bad.

如何在延迟后传递对象的方法?

How can I pass a method with objects after a delay?

推荐答案

p>您可以使用dispatch_after。

You could use dispatch_after.

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self explosionFromPoint:aPoint withSprite:sprite]; 
});

其中aPoint和sprite在块外定义。

Where aPoint and sprite are defined outside of your block.

这篇关于如何将多个对象传递到延迟方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆