public class GameLevel
- Object
- GameLevel
A saved, mode-aware game level or map: the data the visual editor writes and the runtime loads, deliberately decoupled from how it is drawn.
A level has a #getMode() – Mode#TWO_D (tiles + sprites), Mode#THREE_D (meshes in a
perspective world with terrain and lights) or Mode#BOARD (an isometric grid) –
an #getAssetPack() it draws from, a grid size, ordered Layers, freely placed
GameElements, and mode-specific extras (a camera rig, #lights(),
#getTerrain()). It is pure data: load it with #load(String), edit it,
#toJson() it back. Turning it into live objects is the realizer’s job –
#realizeSprites(Scene, AssetCatalog) builds the 2D / board sprites here, while
GameSceneView wires the full lifecycle (including the 3D camera and lights, which
need the GPU device).
Nested types
enum GameLevel.Mode | The kind of a level, which decides how its elements are realized and rendered. |
Constructors
public GameLevel() | |
public GameLevel(GameLevel.Mode mode) |
Methods
Inherited methods
Constructor details
GameLevel
public GameLevel()GameLevel
public GameLevel(GameLevel.Mode mode)Method details
getMode
public GameLevel.Mode getMode()Mode.setMode
public GameLevel setMode(GameLevel.Mode mode)is2D
public boolean is2D()Mode#TWO_D).is3D
public boolean is3D()Mode#THREE_D).isBoard
public boolean isBoard()Mode#BOARD).getAssetPack
public String getAssetPack()AssetPack this level’s elements draw from.setAssetPack
public GameLevel setAssetPack(String assetPack)#getAssetPack()).getCols
public int getCols()getRows
public int getRows()getTileSize
public int getTileSize()setGrid
public GameLevel setGrid(int cols, int rows, int tileSize)props
public Map<String, Object> props()getDouble
public double getDouble(String key, double def)Number/numeric String, else def.getInt
public int getInt(String key, int def)Number/numeric String, else def.getString
public String getString(String key, String def)toString()), or def if absent.layers
public List<Layer> layers()Layer stack (low band first); mutable.addLayer
public GameLevel addLayer(Layer layer)getLayer
public Layer getLayer(String name)null if there is none.elements
public List<GameElement> elements()GameElements, across all layers; mutable.addElement
public GameLevel addElement(GameElement element)lights
public List<LevelLight> lights()getTerrain
public TerrainGrid getTerrain()setTerrain
public GameLevel setTerrain(TerrainGrid terrain)getWorld
public GameWorld getWorld()StreamingTerrain is the authoritative terrain and the
bounded #getTerrain() grid is unused. Serialized inline under the “world” key.setWorld
public GameLevel setWorld(GameWorld world)isLargeWorld
public boolean isLargeWorld()GameWorld of regions rather than a
single bounded grid.setCamera
public GameLevel setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ)setLens
public GameLevel setLens(float fov, float near, float far)getEyeX
public float getEyeX()getEyeY
public float getEyeY()getEyeZ
public float getEyeZ()getTargetX
public float getTargetX()getTargetY
public float getTargetY()getTargetZ
public float getTargetZ()getFov
public float getFov()getNear
public float getNear()getFar
public float getFar()realizeSprites
public void realizeSprites(Scene scene, AssetCatalog catalog)Builds Sprites for the 2D / board content of this level and adds them to the
scene: every painted tile of each visible Layer.Kind#TILE layer plus every
GameElement whose layer is an entity layer. Each sprite’s z-order is its
layer band times 1000 (so a higher layer always draws on top), and its
Sprite#getUserData() is the source GameElement (for tiles, the source
Layer), so an editor can map a picked sprite back to its data.
In Mode#THREE_D this is a no-op (3D content is realized by GameSceneView once the
GPU device exists). In Mode#BOARD positions go through projection (board
elements store their column/row in x/y), so pass a fitted IsoProjection.
realizeSprites
public void realizeSprites(Scene scene, AssetCatalog catalog, IsoProjection projection)load
public static GameLevel load(String json)
throws IOExceptionThrows
load
public static GameLevel load(InputStream in)
throws IOExceptionThrows
toJson
public String toJson()#load(String)).save
public void save(OutputStream out)
throws IOException