Package-level declarations

Types

Link copied to clipboard
class BodyDefinition : BodyDef

Box2D building DSL utility class. BodyDef extension storing FixtureDef instances in fixtureDefinitions collection. Provides inlined building methods that construct fixture definitions.

Link copied to clipboard
Link copied to clipboard
class FixtureDefinition : FixtureDef

Box2D building DSL utility class. FixtureDef extension exposing new properties. Note that when using fixture builders from BodyDefinition, FixtureDefinition.shape field should not be modified - fixture's shape of the chosen type will already be set in the FixtureDefinition instance.

Link copied to clipboard
typealias KtxQueryCallback = (fixture: Fixture) -> Boolean

Callback lambda for querying with an AABB.

Link copied to clipboard
typealias KtxRayCastCallback = (fixture: Fixture, point: Vector2, normal: Vector2, fraction: Float) -> Float

Callback lambda for ray-casts.

Link copied to clipboard
object Query

Stores constants that can be returned by KtxQueryCallback to control its behavior.

Link copied to clipboard
object RayCast

Stores constants that can be returned by KtxRayCastCallback to control its behavior.

Properties

Link copied to clipboard
val earthGravity: Vector2

Roughly matches Earth gravity of 9.80665 m/s^2. Moves bodies down on the Y axis.

Functions

Link copied to clipboard
inline fun World.body(type: BodyDef.BodyType = BodyType.StaticBody, init: BodyDefinition.() -> Unit = {}): Body

Type-safe Body building DSL.

Link copied to clipboard
inline fun Body.box(width: Float = 1.0f, height: Float = 1.0f, position: Vector2 = Vector2.Zero, angle: Float = 0.0f, init: FixtureDefinition.(PolygonShape) -> Unit = {}): Fixture
inline fun BodyDefinition.box(width: Float = 1.0f, height: Float = 1.0f, position: Vector2 = Vector2.Zero, angle: Float = 0.0f, init: FixtureDefinition.(PolygonShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with PolygonShape set as box. Note that - contrary to PolygonShape.setAsBox methods - this method consumes actual not halved box width and height sizes.

Link copied to clipboard
inline fun Body.chain(vararg vertices: Vector2, init: FixtureDefinition.(ChainShape) -> Unit = {}): Fixture
inline fun BodyDefinition.chain(vararg vertices: Vector2, init: FixtureDefinition.(ChainShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with ChainShape.

inline fun Body.chain(vertices: FloatArray, init: FixtureDefinition.(ChainShape) -> Unit = {}): Fixture
inline fun BodyDefinition.chain(vertices: FloatArray, init: FixtureDefinition.(ChainShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with ChainShape. Note that this method consumes a FloatArray instead of array of Vector2 instances, which might be less readable, but creates slightly less garbage. This method is advised to be used instead of the Vector2-consuming variant on mobile devices.

Link copied to clipboard
inline fun Body.circle(radius: Float = 1.0f, position: Vector2 = Vector2.Zero, init: FixtureDefinition.(CircleShape) -> Unit = {}): Fixture
inline fun BodyDefinition.circle(radius: Float = 1.0f, position: Vector2 = Vector2.Zero, init: FixtureDefinition.(CircleShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with CircleShape.

Link copied to clipboard
fun World.create(bodyDefinition: BodyDefinition): Body

Handles additional building properties provided by BodyDefinition and FixtureDefinition. Prefer this method over World.createBody when using BodyDefinition directly.

Link copied to clipboard
fun createWorld(gravity: Vector2 = Vector2.Zero, allowSleep: Boolean = true): World

World factory function.

Link copied to clipboard
inline fun Body.distanceJointWith(body: Body, init: DistanceJointDef.() -> Unit = {}): DistanceJoint

Allows to create a DistanceJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.edge(from: Vector2, to: Vector2, init: FixtureDefinition.(EdgeShape) -> Unit = {}): Fixture
inline fun BodyDefinition.edge(from: Vector2, to: Vector2, init: FixtureDefinition.(EdgeShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with EdgeShape.

inline fun Body.edge(fromX: Float, fromY: Float, toX: Float, toY: Float, init: FixtureDefinition.(EdgeShape) -> Unit = {}): Fixture
inline fun BodyDefinition.edge(fromX: Float, fromY: Float, toX: Float, toY: Float, init: FixtureDefinition.(EdgeShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with EdgeShape. Note that this method consumes floats instead of Vector2 instances, which might be less concise, but also creates slightly less garbage. This method is advised to be used instead of the Vector2-consuming variant on mobile devices.

Link copied to clipboard
fun FixtureDef.filter(filter: Filter): Filter

Utility extension method for setting up of FixtureDef.filter. Allows to copy an existing Filter instance to avoid copying each property manually.

inline fun FixtureDef.filter(init: Filter.() -> Unit)

Inlined utility extension method for setting up of FixtureDef.filter. Exposes Filter properties under this.

Link copied to clipboard
inline fun <S : Shape> Body.fixture(shape: S, disposeOfShape: Boolean = false, init: FixtureDefinition.(S) -> Unit = {}): Fixture
inline fun <ShapeType : Shape> BodyDefinition.fixture(shape: ShapeType, disposeOfShape: Boolean = false, init: FixtureDefinition.(ShapeType) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures of custom shape type.

Link copied to clipboard
inline fun Body.frictionJointWith(body: Body, init: FrictionJointDef.() -> Unit = {}): FrictionJoint

Allows to create a FrictionJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.gearJointWith(body: Body, init: GearJointDef.() -> Unit = {}): GearJoint

Allows to create a GearJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun <J : JointDef> Body.jointWith(body: Body, jointDefinition: J, init: J.() -> Unit = {}): Joint

Allows to create a Joint with custom JointDef instance. this Body will be set as the JointDef.bodyA.

Link copied to clipboard
inline fun Body.loop(vararg vertices: Vector2, init: FixtureDefinition.(ChainShape) -> Unit = {}): Fixture
inline fun BodyDefinition.loop(vararg vertices: Vector2, init: FixtureDefinition.(ChainShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with looped ChainShape.

inline fun Body.loop(vertices: FloatArray, init: FixtureDefinition.(ChainShape) -> Unit = {}): Fixture
inline fun BodyDefinition.loop(vertices: FloatArray, init: FixtureDefinition.(ChainShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with looped ChainShape. Note that this method consumes a FloatArray instead of array of Vector2 instances, which might be less readable, but creates slightly less garbage. This method is advised to be used instead of the Vector2-consuming variant on mobile devices.

Link copied to clipboard
inline fun Body.motorJointWith(body: Body, init: MotorJointDef.() -> Unit = {}): MotorJoint

Allows to create a MotorJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.mouseJointWith(body: Body, init: MouseJointDef.() -> Unit = {}): MouseJoint

Allows to create a MouseJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.polygon(vararg vertices: Vector2, init: FixtureDefinition.(PolygonShape) -> Unit = {}): Fixture
inline fun BodyDefinition.polygon(vararg vertices: Vector2, init: FixtureDefinition.(PolygonShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with PolygonShape.

inline fun Body.polygon(vertices: FloatArray? = null, init: FixtureDefinition.(PolygonShape) -> Unit = {}): Fixture
inline fun BodyDefinition.polygon(vertices: FloatArray? = null, init: FixtureDefinition.(PolygonShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with PolygonShape. Note that this method consumes a FloatArray instead of array of Vector2 instances, which might be less readable, but creates slightly less garbage. This method is advised to be used instead of the Vector2-consuming variant on mobile devices.

Link copied to clipboard
inline fun Body.prismaticJointWith(body: Body, init: PrismaticJointDef.() -> Unit = {}): PrismaticJoint

Allows to create a PrismaticJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.pulleyJointWith(body: Body, init: PulleyJointDef.() -> Unit = {}): PulleyJoint

Allows to create a PulleyJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
fun World.query(lowerX: Float, lowerY: Float, upperX: Float, upperY: Float, callback: KtxQueryCallback)

Query the world for all fixtures that potentially overlap the provided AABB (Axis-Aligned Bounding Box).

Link copied to clipboard
fun World.rayCast(start: Vector2, end: Vector2, callback: KtxRayCastCallback)
fun World.rayCast(startX: Float, startY: Float, endX: Float, endY: Float, callback: KtxRayCastCallback)

Ray-cast the world for all fixtures in the path of the ray.

Link copied to clipboard
inline fun Body.revoluteJointWith(body: Body, init: RevoluteJointDef.() -> Unit = {}): RevoluteJoint

Allows to create a RevoluteJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.ropeJointWith(body: Body, init: RopeJointDef.() -> Unit = {}): RopeJoint

Allows to create a RopeJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.weldJointWith(body: Body, init: WeldJointDef.() -> Unit = {}): WeldJoint

Allows to create a WeldJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.

Link copied to clipboard
inline fun Body.wheelJointWith(body: Body, init: WheelJointDef.() -> Unit = {}): WheelJoint

Allows to create a WheelJoint. this Body will be set as the JointDef.bodyA and will be available through Joint.getBodyA.