我想更新我的旧游戏,使用Swift 2.0。当我尝试修复它时,Xcode发现了一个错误。错误出现在这行代码上:Value of type 'Set' has no member 'anyObject'。
var touch:UITouch = touches.anyObject() as! UITouch
功能:
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.runAction(SKAction.playSoundFileNamed("torpedo.mp3", waitForCompletion: false))
var touch:UITouch = touches.anyObject() as! UITouch //<-- Here is Error
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))
}
那么这里需要修复什么?