forEach

inline fun forEach(action: (Particle) -> Unit)(source)

Calls action with every particle alive, in slot order. action may remove the particle it is given, but must not add any.

Samples

val world = PhysicsWorld()
repeat(3) { world.particles.add(x = it * 10f, y = 0f) }
var sum = 0f
world.particles.forEach { p -> sum += world.particles.xOf(p) }
assertPrints(sum, "30.0")