代码:
var tree = SKSpriteNode(imageNamed: "tree3")//tree3.png is the image
tree.position = CGPointMake(400, movingGround.size.height/2 + tree.size.height/2)
tree.zPosition = -0.5
self.addChild(tree)
func treeMove(){
var moveLeft = SKAction.moveByX(-5, y: 0, duration: 1.0)
tree3.runAction(SKAction.repeatActionForever(moveLeft))
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
treeMove()
}
错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
(LLDB) 如何改进我的代码 提前谢谢
答案 0 :(得分:0)
您在runAction
上呼叫tree3
,但您的SKSpriteNode
名为tree
。
答案 1 :(得分:0)
tree3未初始化。你有没有在其他地方初始化?您尝试实施的预期逻辑是什么? tree3和tree应该是同一个对象还是不同的对象?