I want to animate to the direction of the way the SKSpriteNode is going, but I made a SKsprite which is spawned in random positions and moves randomly, then can be pushed around by the player.
I can't seem to remember how to capture the previous position of the random sprite!
If someone knows how, then I could easily minus current position and can animate the random direction using something like this:
distanceBetweenPoints = hypot(second.x - first.x, second.y - first.y)
Below is my random sprite. I can print the SPball.position in x and y and watch all the numbers go by that I need..lol.
Your help would be greatly appreciated!
func spawnSPball(){
SPball = SKSpriteNode(imageNamed: "Balloon10")
SPball.name = "BALLOON"
SPball.size = CGSize(width: 60, height: 60)
SPball.position = CGPoint(x: random(min: bkgn.frame.minX, max: bkgn.frame.maxX),
y: random(min: bkgn.frame.minY, max: bkgn.frame.maxY))
SPball.physicsBody = SKPhysicsBody(circleOfRadius: 30)
SPball.physicsBody?.restitution = 1.0
SPball.physicsBody?.isDynamic = true
SPball.physicsBody?.affectedByGravity = false
SPball.physicsBody?.allowsRotation = true
SPball.physicsBody?.velocity = (self.physicsBody?.velocity)!
let ReverseMove = SKAction.move(by: REVrandom(), duration: 6)
let rotateSprite = SKAction.rotate(byAngle: 90, duration: 0.5)
let moveAction = SKAction.move(by: randomMove3(), duration: 2)
let impulseAction = SKAction.applyImpulse(randomMove3() , duration: 0.5)
let seqgroup = SKAction.sequence([impulseAction, ReverseMove, rotateSprite,moveAction])
SPball.run(SKAction.repeatForever(seqgroup))
addChild(SPball)
}
Aucun commentaire:
Enregistrer un commentaire