我正面臨Sprite-Kit和Swift 1.2的一個奇怪問題。我有以下代碼。屏幕中間正確顯示fingerSprite
。Sprite-Kit:SKAction.move根本不工作
但是,當我應用moveTo
操作時,沒有任何反應。我對Sprite-Kit和Swift很新,所以我可能會做一些完全愚蠢的事情,但請與我一起裸露。
我在做什麼錯?
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
tutorialStepReset()
var bounceLabels = SKAction.sequence([
SKAction.scaleTo(1.3, duration: 0.5),
SKAction.scaleTo(1.0, duration: 0.5)
])
var fingerPoint = CGPoint(x: self.size.width/2, y: self.size.height/2)
var fingerSprite = SKSpriteNode(imageNamed: "finger.png")
switch tutorialGuideIndex {
case 0: self.runAction(SKAction.runBlock({
self.labelScore.runAction(SKAction.repeatActionForever(bounceLabels))
}))
case 1: self.runAction(SKAction.runBlock({
self.labelUntilNextLevel.runAction(SKAction.repeatActionForever(bounceLabels))
}))
case 2: self.runAction(SKAction.runBlock({
self.labelCurrentLevel.runAction(SKAction.repeatActionForever(bounceLabels))
}))
case 3:
fingerSprite.position = fingerPoint
fingerSprite.zPosition = labelZPosition
self.addChild(fingerSprite)
case 4:
//move finger & draw line
fingerPoint.x = fingerPoint.x+20
fingerPoint.y = fingerPoint.y+20
fingerSprite.runAction(SKAction.scaleTo(2.0, duration: 4.0))
fingerSprite.runAction(SKAction.moveTo(fingerPoint, duration: 4.0))
tutorialGuideIndex++
}
你在哪裏精靈添加到含節點,當你運行的操作?從您發佈的代碼中,精靈不會被添加到任何節點... – giorashc
好點giorashc!我重構了這個例子。基本上我正在開始工作,方法。 – user594883
發佈與fingerSprite相關的整個方法 – Wraithseeker