BodyDefinition

class BodyDefinition : BodyDef

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

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var creationCallback: (Body) -> Unit?

Invoked after the Body is fully constructed.

Link copied to clipboard
Link copied to clipboard

Stores FixtureDefinition instances of all currently defined fixtures of this body. Should not be modified manually - instead, use fixture or one of building methods for fixtures of a specific shape.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val linearVelocity: Vector2
Link copied to clipboard
val position: Vector2
Link copied to clipboard
var type: BodyDef.BodyType
Link copied to clipboard

Custom data object assigned to Body.getUserData. Allows to store additional data about the Body without having to override the class. Defaults to null.

Functions

Link copied to clipboard
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 BodyDefinition.chain(vararg vertices: Vector2, init: FixtureDefinition.(ChainShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with ChainShape.

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 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
inline fun BodyDefinition.edge(from: Vector2, to: Vector2, init: FixtureDefinition.(EdgeShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with EdgeShape.

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
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 BodyDefinition.loop(vararg vertices: Vector2, init: FixtureDefinition.(ChainShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with looped ChainShape.

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
fun onCreate(callback: (Body) -> Unit)
Link copied to clipboard
inline fun BodyDefinition.polygon(vararg vertices: Vector2, init: FixtureDefinition.(PolygonShape) -> Unit = {}): FixtureDefinition

Utility builder method for constructing fixtures with PolygonShape.

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.