I tried to move random my sprites (the squares) but all sprite go to same position and ״vibrating״. What is the best way to move sprite forever and with random position?
//Make random shape
func makeShape () {
//Check if have more than 12 shapes
if shapesamount <= 4 {
sprite = shape.copy() as! SKShapeNode
sprite.name = "Shpae \(shapesamount)"
shapes.addChild(sprite)
shapesamount += 1
moveRandom(node: sprite)
}
}
//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(move)
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
if istouching && !isOver {
let dt:CGFloat = 1.0/50.0
let distance = CGVector(dx: touchpoint.x - circle.position.x, dy: touchpoint.y - circle.position.y)
let velocity = CGVector(dx: distance.dx/dt, dy: distance.dy/dt)
self.circle.physicsBody!.velocity = velocity
}
if isOver == false {
for nodee in shapes.children {
moveRandom(node: nodee as! SKShapeNode)
}
}
}
}
shapes is SKNode
Aucun commentaire:
Enregistrer un commentaire