Levels¶
In Zeta, a level contains and manages every entity, and levels themselves are handled by a LevelScreen.
How to access the level objects¶
Level functionality is split between several classes: the Level, the LevelRenderer and the LevelPhysics. They all have accessors in the LevelScreen class. For example, to get the level renderer, write LevelScreen.getInstance().getLevelRenderer(). You can hook the constructors of both Level and LevelRenderer.
Level object¶
User functions¶
Here are some useful methods in the level object.
- find
- Allows you to find entities that match a class or superclass, and optionally also a name.
- entityExists
- Allows you to tell whether an entity is currently in the level. If not, that entity won’t be saved properly.
Internal functions¶
These functions are called internally and shouldn’t normally be used. Alternatives are listed.
- addEntity
- Use EntityFactory.generate.
- removeEntity
- Use Entity.die.
- reorder
- Use Entity.setPos to let Zeta reorder the entity within the z-order.
- update
- Called automatically every frame by Zeta internally.
Level renderer object¶
User functions¶
- unproject
- Allows you to project UI coordinates (where (0, 0) is the bottom left, and the window dimensions dictate the size) into in-game coordinates (which is, for example, the coordinate system entities are stored in).
- getMouseCoords
- Returns the UI coordinates of the mouse.
- getUnprojectedMouseCoords
- Allows you to find the location of the mouse pointer in game coordinates.
Internal functions¶
- render
- Called automatically every frame by Zeta internally.
- resize
- Called automatically whenever the window changes size by Zeta internally.
- dispose
- Called automatically when the level is exiting by Zeta internally.
Level physics object¶
User functions¶
- collideAny(Solid)
- Returns the first entity whose physics object intersected the provided entity’s physics object. If the solid variant is called, only solid physics objects count. It returns null if no object was hit.
- collideAll(Solid)
- Returns the list of all entities whose physics objects intersected the provided entity’s physics object. It returns an empty list if no object was hit.
- collideAnyCharacter
- Returns the first GameCharacter whose physics object intersected the provided entity’s physics object. It returns null if no object was hit.