vendredi 13 octobre 2017

Argument passed to call that takes no arguments error in swift 4

I have been looking around for a solution to this error within my code but I can't find any solutions.

Here is part of the GameScene.swift file:

func spawnEnemy() {

    let randomXStart = random(min: gameArea.minX, max: gameArea.maxX)
    let randomXEnd = random(min: gameArea.minX, max: gameArea.maxX)

    let startPoint = CGPoint(x: randomXStart, y: self.size.height * 1.2)
    let endPoint = CGPoint(x: randomXEnd, y: -self.size.height * 0.2)

    let enemy = SKSpriteNode(imageNamed: "enemyShip")
    enemy.setScale(1)
    enemy.position = startPoint
    enemy.zPosition = 2
    self.addChild(enemy)

    let moveEnemy = SKAction.moveTo(x: endPoint, duration: 1.5)
    let deleteEnemy = SKAction.removeFromParent()
    let enemySequence = SKAction.sequence([moveEnemy, deleteEnemy])
    enemy.run(enemySequence)

    let dx = endPoint.x - startPoint.x
    let dy = endPoint.y - startPoint.y
    let amountToRotate = atan2(dy, dx)
    enemy.zRotation = amountToRotate

}

In these two lines of code I get the error "Argument passed to call that takes no arguments":

 let randomXStart = random(min: gameArea.minX, max: gameArea.maxX)
    let randomXEnd = random(min: gameArea.minX, max: gameArea.maxX)

Does anyone have a solution?




Aucun commentaire:

Enregistrer un commentaire