键入[String]的Swift 3.0在线教程错误

时间:2017-01-12 05:09:54

标签: ios swift gameplay-kit

我是一般的编程新手。

我决定通过在线教程学习,并且一直在关注Youtube的教程,创建一个类似(bootleg galaga)的游戏。

我检查了所有内容,但我不确定我做错了什么或者是否有Xcode更新。我该如何解决这个问题,以便完成本教程?

代码:

import SpriteKit
import GameplayKit

class GameScene: SKScene, SKPhysicsContactDelegate {

    var starfield:SKEmitterNode!
    var player:SKSpriteNode!

    var scoreLabel:SKLabelNode!
    var score:Int = 0 {
        didSet {
            scoreLabel.text = "Score:\(score)"
        }
    }
    var possibleAliens = ("alien", "alien2", "alien3")
    var gameTimer:Timer!



    override func didMove(to view: SKView) {

        starfield = SKEmitterNode(fileNamed: "Starfield")
        starfield.position = CGPoint(x: 0, y: 1472)
        starfield.advanceSimulationTime(10)
        self.addChild(starfield)

        starfield.zPosition = -1

        player = SKSpriteNode(imageNamed: "shuttle")
        player.position = CGPoint(x: 0, y: -1*player.size.height/2 - 500)
        self.addChild(player)
        self.physicsWorld.gravity = CGVector(dx: 0, dy: 0)
        self.physicsWorld.contactDelegate = self


        scoreLabel = SKLabelNode(text: "Score: 0")
        scoreLabel.position = CGPoint(x: -300, y: -1*player.size.height/2 + 600)
        scoreLabel.fontName = "AmericanTypewriter-Bold"
        scoreLabel.fontSize = 36
        scoreLabel.fontColor = UIColor.white
        score = 0

        self.addChild(scoreLabel)



        gameTimer = Timer.scheduledTimer(timeInterval: 0.75, target: self, selector: #selector(addAlien), userInfo: nil, repeats: true)

    }

    func addAlien () {

      possibleAliens = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: possibleAliens) as! [String]   
    }

错误:

  possibleAliens = GKRandomSource.sharedRandom().arrayByShufflingObjects(in: possibleAliens) as! [String]
  

“无法将类型'(String,String,String)'的值转换为预期的参数类型'[Any]'

1 个答案:

答案 0 :(得分:0)

你做到了  var possibleAliens =(“alien”,“alien2”,“alien3”)

试  var possibleAliens = [“alien”,“alien2”,“alien3”]