what does this mean?!? "Argument passed to call that takes no arguments"

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
   
Answered by DTS Engineer in 780487022

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"

Pro tip 1: Don’t use legacy Objective-C functions CGRectGetMinX() and CGRectGetMaxX() in Swift code; use gameArea.minX and gameArea.maxX which are equivalent but modern and Swifty.

Pro tip 2: Always start variable names with a lowercase letter, so dino instead of Dino. Breaking this naming convention can really confuse experienced Swift programmers trying to read the code.

btw im just following a video so please dumb it down for me

Pro tip 3: Be wary of any tutorial or video (on any programming topic) that’s more than a few years old. They often don’t age well. Yours appears to be one that is almost 8 years old. It looks pretty good overall (after just glancing over a couple of the episodes) but as you can see the actual APIs have evolved since then.

BTW, another forum user was working off the same video and already performed some of this modernization. See this thread.

And to answer the actual original question: arc4random() indeed doesn’t take any arguments. Why is that there? The video uses a function called random() which is defined elsewhere in the code. And (no surprise) the API for generating pseudo-random numbers has evolved since then anyway.

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<CGFloat>' 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
Accepted Answer

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"

what does this mean?!? "Argument passed to call that takes no arguments"
 
 
Q