问题描述
我和斯威夫特SpriteKit试验,但不知何故似乎无法创建一个序列中使用动作的数组。我已经把它分解到尝试和针点的问题,但至今没有运气。
I'm experimenting with SpriteKit in Swift but somehow seem unable to create an array of actions to use in a sequence. I've split it up to try and pin-point the problem, but no luck so far.
func animateBackground(){
let moveLeft = SKAction.moveByX(100, y: 0, duration: 3)
moveLeft.timingMode = SKActionTimingMode.EaseInEaseOut
let moveRight = SKAction.reversedAction(moveLeft)
let actions = [moveLeft, moveRight] // <--- here there be dragons/trouble
let sequence = SKAction.sequence(actions)
let repeat = SKAction.repeatActionForever(sequence)
}
在试图创建行动阵列我得到错误的不能转换前pression的类型'阵'输入'ArrayLiteralConvertible'的所以,我想我可能需要更明确,并试图将其更改为
When trying to create the actions-array I get the error "Cannot convert the expression's type 'Array' to type 'ArrayLiteralConvertible' " So, I thought I might need to be more explicit and attempted to change it to
var actions: SKAction[] = [moveLeft, moveRight]
这似乎降低了房子,而不是一个好办法,导致<一个href=\"http://stackoverflow.com/questions/24063055/error-x$c$c-6-error-sourcekit-terminated-editor-functionality-temporaly-lim\">SourceKit终止错误...
This seemed to bring down the house, and not in a good way, resulting in the SourceKit terminated bug...
推荐答案
您要添加一个功能到数组用于MoveRight的,而不是SKAction本身。尝试使用这个代替:
You're adding a function to the array for moveRight, not the SKAction itself. Try using this instead:
let moveRight = SKAction.reversedAction(moveLeft)()
这篇关于无法创建SKActions数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!