0

I created the player class with:

class Player : SKSpriteNode, GameSprite {
    var initialSize = CGSize(width:50, height:50 )
    var textureAtlas: SKTextureAtlas = SKTextureAtlas(named: "Dino")
    func onTap()
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}

I then tried to add an instance of the player class in GameScene.swift with:

class GameScene: SKScene {
    override func didMove(to view: SKView) {
        self.anchorPoint = .zero
        self.backgroundColor = UIColor(red: 0.95, green: 0.1, blue: 0.25, alpha: 1.0)
        let player = Player()
        player.size = CGSize(width: 50, height: 50)
        player.position = CGPoint(x: self.size.width / 2, y: self.size.height / 2)
        self.addChild(player)
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch in (touches) {
            let location = touch.location(in: self)
            let nodeTouched = atPoint(location)
            if let gameSprite = nodeTouched as? GameSprite {
                gameSprite.onTap()
            }
        }
    }
}

But an error occurred saying:

Missing argument for parameter 'coder' in call

In the line that reads let player = Player()

Thanks!

GMachado
  • 791
  • 10
  • 24
  • The Player class is a subclass of GameSprite? It doesn't sound right. – El Tomato Sep 11 '18 at 02:01
  • 1
    Possible duplicate of [Missing Argument for parameter ‘coder’ in call](https://stackoverflow.com/questions/35738383/missing-argument-for-parameter-coder-in-call) – l'L'l Sep 11 '18 at 02:01

0 Answers0