Ios 运行序列时动态分配操作参数
我偶然发现了一个问题,却找不到答案。我正在使用Xcode的SK模板创建一个iOS游戏。我是初学者,请耐心听我说 基本上我有这个代码:Ios 运行序列时动态分配操作参数,ios,iphone,sprite-kit,duration,skaction,Ios,Iphone,Sprite Kit,Duration,Skaction,我偶然发现了一个问题,却找不到答案。我正在使用Xcode的SK模板创建一个iOS游戏。我是初学者,请耐心听我说 基本上我有这个代码: SKAction *releaseBubbles = [SKAction sequence:@[ [SKAction performSelector:@selector(createBubbleNode)onTarget:self],
SKAction *releaseBubbles = [SKAction sequence:@[
[SKAction performSelector:@selector(createBubbleNode)onTarget:self],
[SKAction waitForDuration:speed]]];
[self runAction: [SKAction repeatAction:releaseBubbles
count:300]];
它在
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
我在-(void)touchsbegind:(NSSet*)touchsevent:(UIEvent*)event{
中更改游戏的级别,当我更改级别时,它也应该更改速度参数。当然,这不起作用,因为我相信我的动作是在场景初始化时开始的,我永远无法切换参数
我需要做的是在屏幕上不断填充气泡,气泡以一定的速度出现(相对于级别)
我真的不知道如何解决这个问题,因为我觉得我需要停止并重新启动动作序列
期待您有价值的输入。要在屏幕上连续填充气泡,您可以使用
SKScene
的更新:
方法。下面介绍如何操作
首先,添加一个属性,该属性将存储上次添加气泡的日期
@property(nonatomic, strong) NSDate *lastBubbleCreationDate;
然后,将更新:
方法更改为:
-(void)update:(CFTimeInterval)currentTime
{
// Create new bubble every 5s.
if (ABS([_lastBubbleCreationDate timeIntervalSinceNow]) > 5)
{
[self createBubbleNode];
}
}
最后,在createBubbleNode
方法中,必须存储上次创建气泡的时间:
-(void)createBubbleNode
{
// Your code here
// Set the date to now.
_lastBubbleCreationDate = [NSDate date];
}
您还需要调用createBubbleNode
来设置\u lastBubbleCreationDate
的初始值。您可以在didMoveToView:
方法中执行此操作。只需将此方法添加到场景实现中:
- (void)didMoveToView:(SKView *)view
{
// Creates first bubble and sets the initial value of the _lastBubbleCreationDate
[self createBubbleNode];
}
在下一个关卡中,您只需更改5s
值,以更频繁地创建气泡,这将使游戏更加困难