我正在尝试编写一个例程来掷骰子。我希望在登陆最终数字之前改变几次脸。下面的代码没有显示换模面。我添加了 sleep 语句,希望它有时间更新,但它只是保留初始面直到结束,然后显示最终面。更改纹理后是否有要添加的语句以强制视图更新?
func rollDice() {
var x: Int
for var i = 0; i < 50; i++
{
x = GKRandomSource.sharedRandom().nextIntWithUpperBound(6)
let texture = dice[0].faces[x]
let action:SKAction = SKAction.setTexture(texture)
pieces[3].runAction(action)
pieces[3].texture = dice[0].faces[x]
NSThread.sleepForTimeInterval(0.1)
print(x)
}
}