swift和spritekit中的倒计时 [英] countdown in swift and spritekit

查看:188
本文介绍了swift和spritekit中的倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将countDown放在我的应用程序上。我正在使用SKLabelNode。这是我的代码:

I'm trying to put a countDown on my application. I'm using a SKLabelNode. This is my code :

class PlayScene: SKScene {
    var startCount = true
    var setTime = 0
    var myTime = 0
    var printTime = SKLabelNode(fontNamed: "arial")
    override func didMoveToView(view: SKView!) {
        self.backgroundColor = UIColor(hex: 0xD64541)
        self.printTime.text = NSString(format: "%i", self.myTime)
        self.addChild(self.printTime)
    }
    override func update(currentTime: NSTimeInterval) {
        if self.startCount == true {
            self.setTime = Int(currentTime)
            self.startCount = false
        }
        self.myTime = Int(currentTime) - self.setTime
        }
  }

我没有编译它的问题,但它在执行时崩溃...
我认为这是来自我在字符串中的转换..

I had no problem to compile it but it's crashing at the execution... I think that's coming from my convertion in string..

谢谢

推荐答案

float  timeforFunction;
   int numberoftime;
   int __totalscore;
   timeforFunction=1.5f;
   numberoftime=10;

    SKAction *updateTime= [SKAction sequence:@[
                                               [SKAction waitForDuration: timeforFunction],
                                               [SKAction performSelector:@selector(updatescore)
                                                                onTarget:self]

                                               ]];
    [self runAction:[SKAction repeatAction:updateTime count: numberoftime] withKey:@"zorbTime"];


   -(void) updatescore
{
    __totalscore+=1;
   _GamescoreText.text = [NSString stringWithFormat:@"%i", __totalscore];
}

如果你想永远重复这个动作,只需改为

if you wanna repeat this action forever just change to

[self runAction:[SKAction repeatAction:updateTime count: numberoftime] withKey:@"zorbTime"];

这篇关于swift和spritekit中的倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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