add
fun add(x: Float, y: Float, mass: Float = 1.0f, radius: Float = 0.0f, bodyCollision: BodyCollision = BodyCollision.PASS, material: Material = Material.DEFAULT): Particle(source)
Adds a particle at (x, y) at rest and returns its handle.
mass is more than 0, or STATIC for a particle nothing moves. radius is how far it keeps out of things, 0 for a point. With BodyCollision.COLLIDE it is kept out of rigid bodies, soft bodies and every other such particle, by their radii, like a grain of sand; with BodyCollision.PASS, the default, it passes through them and only meets the solids. Either way it is kept out of the solids until setSolidCollision says otherwise. Its material says how it grips and bounces. Pass the arguments after y by name.
Throws
Samples
val world = PhysicsWorld()
val spark = world.particles.add(x = 10f, y = 20f)
// A grain of sand: round, and pushed by everything else that collides.
val grain = world.particles.add(x = 30f, y = 20f, mass = 0.5f, radius = 2f, bodyCollision = BodyCollision.COLLIDE)
assertPrints(world.particles.size, "2")
assertPrints(world.particles.xOf(spark), "10.0")
assertPrints(world.particles.inverseMassOf(grain), "2.0")
assertPrints(world.particles.bodyCollisionOf(grain), "COLLIDE")Content copied to clipboard