this is where the problem is let randomXStart = arc4random(min: CGRectGetMinX(gameArea), max: CGRectGetMaxX(gameArea)) let randomXEnd = arc4random(min: CGRectGetMinX(gameArea), max: CGRectGetMaxX(gameArea))
for some reason it says to delete it but when i do, it doesnt work
btw im just following a video so please dumb it down for me
this is all the code for the section it's located in
func spawnEnemy (){
let randomXStart = arc4random(min: CGRectGetMinX(gameArea), max: CGRectGetMaxX(gameArea))
let randomXEnd = arc4random(min: CGRectGetMinX(gameArea), max: CGRectGetMaxX(gameArea))
let startPoint = CGPoint(x: randomXStart, y: self.size.height * 1.2)
let endPoint = CGPoint(x: randomXEnd, y: self.size.height * 0.2)
let Dino = SKSpriteNode(imageNamed: "BlueDino")
Dino.setScale(1)
Dino.position = startPoint
Dino.zPosition = 2
self.addChild(Dino)
let moveDino = SKAction.moveTo(endPoint, duration: 1.5)
let deleteDino = SKAction.removeFromParent()
let dinoSequence = SKAction.sequence([moveDino, deleteDino])
Dino.run(dinoSequence)
let dx = endPoint.x - startPoint.x
let dy = endPoint.y - startPoint.y
let amountToRotate = atan2(dy, dx)
Dino.zRotation = amountToRotate
Scott you absolute legend
Hear hear!
now its saying
You can’t reasonably form a collection from a pair of floating point numbers. It would have a very large number of elements. A better option is this:
let randomXStart = CGFloat.random(in: gameArea.minX...gameArea.maxX)
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"