1
所以我只是在xcode messin周圍,我遇到了一個問題。我創建了一個系統,每當用戶觸摸屏幕上的任何位置時,都會在用戶觸摸的位置創建一個隨機顏色的SKLabel。我怎麼能讓所創建的SKLabel消失,或者說在5秒之後從場景中移除?由於一段時間後刪除SKLabel
import SpriteKit
class GameScene: SKScene {
func createNateLabel(touchLocation: CGPoint){
let nate = SKLabelNode(fontNamed: "Chalduster")
let randomNumber = Int(arc4random_uniform(UInt32(8)))
if randomNumber == 0 {
nate.fontColor = UIColor.cyanColor()
}
if randomNumber == 1{
nate.fontColor = UIColor.redColor()
}
if randomNumber == 2{
nate.fontColor = UIColor.blueColor()
}
if randomNumber == 3{
nate.fontColor = UIColor.purpleColor()
}
if randomNumber == 4{
nate.fontColor = UIColor.yellowColor()
}
if randomNumber == 5{
nate.fontColor = UIColor.greenColor()
}
if randomNumber == 6{
nate.fontColor = UIColor.orangeColor()
}
if randomNumber == 7{
nate.fontColor = UIColor.darkGrayColor()
}
if randomNumber == 8{
nate.fontColor = UIColor.yellowColor()
}
if nate == true{
let wait = SKAction.waitForDuration(3)
nate.runAction(wait)
nate.removeAllChildren()
}
nate.text = "Nate"
nate.fontSize = 35
nate.position = touchLocation
addChild(nate)
}
override func didMoveToView(view: SKView) {
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first! as UITouch
let touchLocation = touch.locationInNode(self)
createNateLabel(touchLocation)
}
}
func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
創建一個計時器來清除它們 –