For my game I need to detect if nodes are still moving or not. Now I try to compare old and new positions within a time interval. If positions have the same value, nodes are not moving. And vice versa. Something like that:
if aStonesPositionsOld[index] == aStonesPositionsNew[index] {
print("# stone \(index) is not moving")
}
Does somebody know the better and easier way to check if node is moving or not?
Update. Answer to question of KnighOfDragon (How nodes begin moving?) Nodes begin to move if being touched, or more exactly - moved with finger. Here is a code:
if touching {
let dt:CGFloat = 1.0/60.0
let distance = CGVector(dx: touchPoint.x-aCuesMe[touchingNr].position.x, dy: touchPoint.y-aCuesMe[touchingNr].position.y)
velocity = CGVector(dx: distance.dx/dt, dy: distance.dy/dt)
aCuesMe[touchingNr].physicsBody!.velocity=velocity
}
Since you are moving the object using the physics engine, all you have to do is check the velocity.
if let v = aCuesMe[someIndex].physicsBody?.velocity {
if v == CGVector(dx: 0, dy: 0) {
// Object has 0 velocity and is not moving
}
}