无法将类型"NSMutableArray"的值转换为预期的参数类型"[SKAction]"
问题描述:
我检查了我的旧游戏(由SpriteKit制造),并想在Swift 2.0中进行更新.当我尝试修复它时,Xcode发现一个错误.
I checked my old game (made in SpriteKit) and I want to update it in Swift 2.0. When I tried to fix it, Xcode found an errors.
错误是:无法将类型'NSMutableArray'的值转换为预期的参数类型'[SKAction]'
在代码中:
torpedo.runAction(SKAction.sequence(actionArray))
功能
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.runAction(SKAction.playSoundFileNamed("torpedo.mp3", waitForCompletion: false))
var touch:UITouch = touches.anyObject() as! UITouch
var location:CGPoint = touch.locationInNode(self)
var torpedo:SKSpriteNode = SKSpriteNode(imageNamed: "torpedo")
torpedo.position = player.position
torpedo.physicsBody = SKPhysicsBody(circleOfRadius: torpedo.size.width/2)
torpedo.physicsBody!.dynamic = true
torpedo.physicsBody!.categoryBitMask = photonTorpedoCategory
torpedo.physicsBody!.contactTestBitMask = alienCategory
torpedo.physicsBody!.collisionBitMask = 0
torpedo.physicsBody!.usesPreciseCollisionDetection = true
var offset:CGPoint = vecSub(location, b: torpedo.position)
if (offset.y < 0){
return
self.addChild(torpedo)
var direction:CGPoint = vecNormalize(offset)
var shotLength:CGPoint = vecMult(direction, b: 1000)
var finalDestination:CGPoint = vecAdd(shotLength, b: torpedo.position)
let velocity = 568/1
let moveDuration:Float = Float(self.size.width) / Float(velocity)
var actionArray:NSMutableArray = NSMutableArray()
actionArray.addObject(SKAction.moveTo(finalDestination, duration: NSTimeInterval(moveDuration)))
actionArray.addObject(SKAction.removeFromParent())
torpedo.runAction(SKAction.sequence(actionArray)) //<-- Here is Error
}
有人可以帮助我吗?
答
要执行一系列操作,请使用此代码
To run a sequence of actions use this code
// REMOVE THIS var actionArray:NSMutableArray = NSMutableArray()
let move = SKAction.moveTo(finalDestination, duration: NSTimeInterval(moveDuration))
let remove = SKAction.removeFromParent()
torpedo.runAction(SKAction.sequence([move,remove]))