I am making a game in Swift, and I need the "frowny" to spawn at random positions on the screen then fall through, I have it spawning but its only in one section and it won't spawn anywhere else. :
}
func random() -> CGFloat {
return CGFloat(Float(arc4random()) / 0xFFFFFFFFFFFFF)
}
func random(#min: CGFloat, max: CGFloat) -> CGFloat {
return random() * (max - min) + min
}
func addFrowny() {
let frowny = SKSpriteNode(imageNamed: "Frowny")
let actualX = random(min: frowny.size.width/2, max: size.width + frowny.size.height/2)
frowny.position = CGPoint(x: actualX, y: size.width - frowny.size.height/2)
addChild(frowny)
let actualDuration = random(min: CGFloat(2.0), max: CGFloat(4.0))
let actionMove = SKAction.moveTo(CGPoint(x: actualX, y: +frowny.size.height/2), duration: NSTimeInterval(actualDuration))
let actionMoveDone = SKAction.removeFromParent()
frowny.runAction(SKAction.sequence([actionMove, actionMoveDone]))
Aucun commentaire:
Enregistrer un commentaire