dimanche 15 février 2015

Random movement of sprite in Swift

I'm new here so i apologize if i've entered my question wrongly. That said, i'm having an issue making my sprite move into random locations around the screen. here is my code



func random() ->CGFloat{
return CGFloat(Float(arc4random()) / 0xFFFFFFFF)
}
func random(#min: CGFloat, max:CGFloat) ->CGFloat{
return random()*(max-min)+min
}

dino.position = CGPoint(x: size.width + dino.size.width/2, y: actualY)
// Add the monster to the scene
addChild(dino)
// Determine speed of the monster
let actualDuration = random(min: CGFloat(3.0), max: CGFloat(4.0))
let randomNum = CGPoint(x:Int (arc4random()%1000), y:Int (arc4random()%1000))
// Create the actions
var actionMove = SKAction:CGPoint(CGPoint(x:randomNum, y:randomNum)), duration:NSTimeInterval;(actualDuration)
let actionMoveDone = SKAction.removeFromParent()
dino.runAction(SKAction.sequence([actionMove, actionMoveDone]))


thank you for helping, anything helps at this point


Aucun commentaire:

Enregistrer un commentaire