it kind worked and i dont know if youll be able to help but now its saying
Referencing instance method 'randomElement()' on 'ClosedRange' requires that 'CGFloat.Stride' (aka 'CGFloat') conform to 'SignedInteger'
Requirement from conditional conformance of 'ClosedRange' to 'Collection' (Swift.ClosedRange)
this is the code with the problem
let randomXStart = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.minX
let randomXEnd = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.maxX
help
this is all the code
func spawnEnemy (){
print("Start spawn")
let randomXStart = (gameArea.minX...gameArea.maxX).randomElement() ?? gameArea.minX
let randomXEnd = (gameArea.minX...gameArea.maxX).randomElement() ?? 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 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)
print("dx", dx, "dy", dy, "rotation", amountToRotate)
dino.zRotation = amountToRotate
Topic:
App & System Services
SubTopic:
General
Tags: