vendredi 12 mai 2017

Sprite move once time in random positions

I tried to move sprites move randomly on screen but the sprite move once time to random position and stop to move

Here I call to make shapes func with timer

    //Make shape Timer
func makeshapetimer () {
    maketimer = Timer.scheduledTimer(timeInterval: 3.0, target: self, selector: #selector(makerandomShape), userInfo: nil, repeats: true)
}

//Make random shape
func makerandomShape () {

    //Check if have more than 12 shapes
    if shapesamount <= 12 {

        let sprite = shape.copy() as! SKShapeNode
        sprite.name = "Shpae \(shapesamount)"
        sprite.position = CGPoint(x: frame.minX - sprite.frame.width, y: frame.maxY)

        shapes.addChild(sprite)

        shapesamount += 1

        moveRandom(node: sprite)
    }
}

And here I make a random position action and repeat the action forever but is run only once time per shape

//Move shape radmonly
func moveRandom (node: SKShapeNode) {

    move = SKAction.move(to: CGPoint(x: CGFloat.random(min: frame.minX, max: frame.maxX), y: CGFloat.random(min: frame.minY, max: frame.maxY)), duration: shapespeed)

    node.run(SKAction.repeatForever(move))
}




Aucun commentaire:

Enregistrer un commentaire