Events

class Events(source)

What happened in the last PhysicsWorld.step.

Touches. contactsBegun and contactsEnded list the things that started and stopped touching: rigid bodies, soft bodies and the solids, in any pair. Loose particles get none, as sand would flood them: they have the readouts below. A touch begins in the step two things first push on each other, or come within TOUCH_SLOP, and ends in the first step they don't, so each comes once, however many substeps and points it has. Two bodies asleep against each other stay touching, and a body that's removed ends its touches in the next step.

Sensors. sensorsEntered and sensorsExited list what came into and went out of a sensor (see RigidBodies.setResponse): rigid bodies, soft bodies and loose particles. The sensor is always Touch.a.

Joints. brokenJointCount and brokenJointAt list the joints that broke.

Particles on floors. Which particles stood on a floor, and the Solid.tags of those floors. It keeps this step and the one before apart, because "can I jump?" asks about before you left the ground. A floor is any solid that pushed the particle up: a surface flatter than 60 degrees. Walls and ceilings push too, but aren't floors and report no tags.

toString gives how many touches of each kind the last step reported, for example Events(contactsBegun=2, contactsEnded=0, sensorsEntered=1, sensorsExited=0, brokenJoints=0).

Samples

val world = PhysicsWorld()
val ground = world.rigidBody(Shape.box(200f, 10f), x = 0f, y = 30f, kind = BodyKind.STATIC)
val ball = world.rigidBody(Shape.circle(5f), x = 0f, y = 0f)
var landed = false
repeat(60) {
    world.step(1.seconds / 60)
    if (world.events.contactsBegun.has(TouchSide.of(ball), TouchSide.of(ground))) landed = true
}
assertPrints(landed, "true")

Properties

Link copied to clipboard

Number of joints that broke in the last step.

Link copied to clipboard

Things that started touching in the last step.

Link copied to clipboard

Things that stopped touching in the last step.

Link copied to clipboard

Things that came into a sensor in the last step: the sensor is each one's Touch.a.

Link copied to clipboard

Things that left a sensor, or were removed while in it, in the last step.

Functions

Link copied to clipboard
fun brokenJointAt(index: Int): Joint

Returns the joint at index of those that broke in the last step. It has been removed, so its slot may be handed out again.

Link copied to clipboard

Returns the unit normal of particle's last contact, across, pointing away from what it touched: (0, -1) on a flat floor. It means something only while isTouching.

Link copied to clipboard

Returns the unit normal of particle's last contact, down: see contactNormalXOf.

Link copied to clipboard

Returns the tags of every floor particle stood on during the last step, together; SolidTags.NONE for none.

Link copied to clipboard
fun isOnFloor(particle: Particle): Boolean

Returns true if particle stood on a floor at any time during the last step.

Link copied to clipboard
fun isTouching(particle: Particle): Boolean

Returns true if particle was pushed out of anything during the last step: a solid, a body or another particle, floor or not.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Returns the particle particle last touched, or the first particle of the edge it touched, or null when it last touched a solid or a rigid body.

Link copied to clipboard
fun wasOnFloor(particle: Particle): Boolean

Returns true if particle stood on a floor during the step before the last, for coyote time.