2015-03-13 70 views
-2

我想创建一个算法,可以增加我的第二个变量的值:每5秒“级别”,但我卡住了。使用时间间隔的算法

// This algorithm wll instill the point system in the game 
    let nextLevel = SKAction.waitForDuration(NSTimeInterval(5.0)) 
    //*Pseudocode: Level increases every 5 seconds 
    // let level = 
+0

...这很容易:用当前系统时间创建一个变量。创建一个新的线程,通过比较当前时间和变量来检查它是什么时间。如果差值为5秒,则更新变量并执行每5秒所需的其他操作。 – ScarletMerlin 2015-03-13 20:11:07

回答

0

使用定时器!

timer = new Timer(5000, increment_var); 
    timer.start(); 

    public int increment_var{ 
     level++; 
    }