SKAction repeatActionForever不产生实体 [英] SKAction repeatActionForever not spawning entity

查看:261
本文介绍了SKAction repeatActionForever不产生实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个生成实体函数,理论上应该将具有某些属性的随机气球生成到屏幕上.我已经设计了这样的方法:

Basically I have a spawn entity function that should in theory, spawn a random balloon onto the screen with certain properties. I have designed the method as such:

-(void)spawnBalloon
{
    int a = arc4random_uniform(self.frame.size.width);
    int b = self.frame.size.height - 50;
    CGPoint loc = CGPointMake(a, b);
    [self spawnBalloonAtPoint:loc];
}

此方法有效.当我在init函数中调用它时,它可以工作.当我在touchesMoved()函数中调用它时,它可以工作.但是,当我尝试在

And this method works. When I call it in the init function, it works. When I call it in the touchesMoved() function it works. However, when I try and call it in the init method with the

[self runAction:[SKAction repeatActionForever:[SKAction performSelector:@selector(spawnBalloon) onTarget:self]]];

失败.为什么是这样?我是否只需要使用自我"中的performSelector函数,然后使用NSTimer使其永久重复?

It fails. Why is this? Do I have to just use a performSelector function from "self" and then use an NSTimer to have it repeat forever?

此外,我尝试将NSLog放入代码中,以查看它是否在重复动作中甚至在执行.唯一的问题是气球没有被添加到屏幕上.我的感觉是,当我通过repeatActionForever调用spawnBalloon函数时,self引用了另一个类?抱歉,如果这令人困惑,我对Objective C和SpriteKit还是陌生的,而不是真正地阅读很多东西,而是决定在需要时学习(但是我对Java/C有广泛的了解)

Also, I tried throwing an NSLog into the code to see if it was even being executed when it was in the repeat action, and it is. The only problem is that the balloon is not being added to the screen. My feeling is that when I call the spawnBalloon function through the repeatActionForever, self refers to a different class ? Sorry if this is confusing, I'm still new to Objective C and SpriteKit, and instead of really reading much I dived in and decided to learn-when-needed (However I have a vast knowledge of Java/C)

我发现,如果我没有repeatForever操作,代码将执行并正常工作.但是,如果它在那里,则不起作用.

I figured out that if I don't have the repeatForever action, the code will execute and work. However, if its there, it doesn't work.

推荐答案

尝试一下:

[self runAction:[SKAction repeatActionForever:[SKAction sequence:@[
                                                                   [SKAction waitForDuration:0.1],
                                                                   [SKAction performSelector:@selector(spawnBalloon) onTarget:self]
                                                                   ]]]];

这篇关于SKAction repeatActionForever不产生实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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