Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public abstract class LevelEntity

  1. Object
  2. LevelEntity

Known subtypesBlockEntity, Checkpoint, Pickup, Projectile, Spring, Switch

Something in a level that is not an actor: a coin, a spring, a door, a projectile, a crumbling block.

An entity is a rectangle with a getType() name that the view maps to art. Each tick the world calls step, and calls onTouch for every living actor that overlaps it. An entity that must block movement (a door, a gate, a crumbling block) writes Tile#SOLID cells into the grid rather than colliding itself, so the controller stays one fast tile scan.

Subclasses must be deterministic, like abilities, and fold any state that changes play into hashState.

Fields

public int xLeft edge, fixed point.
public int yTop edge, fixed point.
public int wWidth, fixed point.
public int hHeight, fixed point.

Constructors

protected LevelEntity(String id, String type, int x, int y, int w, int h)Creates an entity.

Methods

public String getId()The entity’s id.
public String getType()The entity’s kind.
public boolean isActive()Whether the entity still takes part.
public void deactivate()Removes the entity at the end of the tick.
public int getPhase()A small number the view reads to pick a frame: open or closed, lit or not, how cracked.
public int getTouchMargin()How far outside its rectangle the entity still counts as touched.
public void onAdded(PlatformWorld world)Called once when the entity is added to a world, before the first step: the place to write solid cells.
public void step(PlatformWorld world)Advances one tick.
public void onTouch(PlatformWorld world, Actor c)Called each tick a living actor overlaps the entity.
public long hashState(long h)Mixes the entity’s play-relevant state into a hash.

Inherited methods

Field details

x

public int x
Left edge, fixed point.

y

public int y
Top edge, fixed point.

w

public int w
Width, fixed point.

h

public int h
Height, fixed point.

Constructor details

LevelEntity

protected LevelEntity(String id, String type, int x, int y, int w, int h)
Creates an entity.

Parameters

id String
a name, unique in its world
type String
the kind, which the view maps to art ("coin", "spring")
x int
left, fixed point
y int
top, fixed point
w int
width, fixed point
h int
height, fixed point

Method details

getId

public String getId()
The entity’s id.

Returns

the id

getType

public String getType()
The entity’s kind.

Returns

the type name

isActive

public boolean isActive()
Whether the entity still takes part. Inactive entities are skipped and not drawn; the world drops them at the end of the tick.

Returns

true while active

deactivate

public void deactivate()
Removes the entity at the end of the tick.

getPhase

public int getPhase()
A small number the view reads to pick a frame: open or closed, lit or not, how cracked. The default is 0.

Returns

the visual phase

getTouchMargin

public int getTouchMargin()
How far outside its rectangle the entity still counts as touched. An entity that writes solid cells (a door) needs a margin, since an actor can never overlap a solid cell. The default is 0.

Returns

the margin, fixed point

onAdded

public void onAdded(PlatformWorld world)
Called once when the entity is added to a world, before the first step: the place to write solid cells. The default does nothing.

Parameters

world PlatformWorld
the world

step

public void step(PlatformWorld world)
Advances one tick. The default does nothing.

Parameters

world PlatformWorld
the world

onTouch

public void onTouch(PlatformWorld world, Actor c)
Called each tick a living actor overlaps the entity.

Parameters

world PlatformWorld
the world
c Actor
the actor

hashState

public long hashState(long h)
Mixes the entity’s play-relevant state into a hash. The default mixes the position and whether it is active.

Parameters

h long
the running hash

Returns

the updated hash