Hello,
I am fairly new to Xcode & swift.
I have been following a tutorial on YouTube entitled "solo mission"
In this tutorial it uses a slightly older version of Xcode which means some of the code needs to be updated. I have managed to update the code to which there is no errors, but the "spawnEnemy" section is not spawning the enemy's as described in the video.
This is the code I have for the spawning enemy's;
///SPAWNING NOT WORKING///
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.move(to: 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
}
Can anyone help me figure out why this is not working?
Thank you in advance