Class 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 Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe kind of a level, which decides how its elements are realized and rendered. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddElement(GameElement element) Adds a placed element to the level.Appends a layer to the stack.elements()The placedGameElements, across all layers; mutable.The id of theAssetPackthis level's elements draw from.intgetCols()The grid width in cells.doubleA level property as a double, coerced from aNumber/numericString, elsedef.floatgetEyeX()floatgetEyeY()floatgetEyeZ()floatgetFar()floatgetFov()intA level property as an int, coerced from aNumber/numericString, elsedef.The layer with the given name, ornullif there is none.getMode()This level'sMode.floatgetNear()intgetRows()The grid height in cells.A level property as a String (any value'stoString()), ordefif absent.floatfloatfloatintThe size of one grid cell -- pixels per tile in 2D / board, world units per cell in 3D.getWorld()The streaming/region world backing a "large world" level, or null for a bounded level.booleanis2D()True for an orthographic 2D level (Mode#TWO_D).booleanis3D()True for a perspective 3D level (Mode#THREE_D).booleanisBoard()True for an isometric board level (Mode#BOARD).booleanTrue when this level is backed by a streamingGameWorldof regions rather than a single bounded grid.layers()The orderedLayerstack (low band first); mutable.lights()static GameLevelload(InputStream in) Parses a level from a UTF-8 JSON stream and closes it.static GameLevelParses a level from a JSON string.props()The level-wide authoring property bag (gravity, background, ...).voidrealizeSprites(Scene scene, AssetCatalog catalog) BuildsSprites for the 2D / board content of this level and adds them to the scene: every painted tile of each visibleLayer.Kind#TILElayer plus everyGameElementwhose layer is an entity layer.voidrealizeSprites(Scene scene, AssetCatalog catalog, IsoProjection projection) voidsave(OutputStream out) Writes this level as UTF-8 JSON to the stream (does not close it).setAssetPack(String assetPack) Sets the asset-pack id (see#getAssetPack()).setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ) setGrid(int cols, int rows, int tileSize) Sets the grid dimensions and cell size in one call.setLens(float fov, float near, float far) setMode(GameLevel.Mode mode) setTerrain(TerrainGrid terrain) toJson()Serializes this level to a compact JSON string (round-trips through#load(String)).
-
Constructor Details
-
GameLevel
public GameLevel() -
GameLevel
-
-
Method Details
-
getMode
This level'sMode. -
setMode
-
is2D
public boolean is2D()True for an orthographic 2D level (Mode#TWO_D). -
is3D
public boolean is3D()True for a perspective 3D level (Mode#THREE_D). -
isBoard
public boolean isBoard()True for an isometric board level (Mode#BOARD). -
getAssetPack
The id of theAssetPackthis level's elements draw from. -
setAssetPack
-
getCols
public int getCols()The grid width in cells. -
getRows
public int getRows()The grid height in cells. -
getTileSize
public int getTileSize()The size of one grid cell -- pixels per tile in 2D / board, world units per cell in 3D. -
setGrid
Sets the grid dimensions and cell size in one call. -
props
-
getDouble
A level property as a double, coerced from aNumber/numericString, elsedef. -
getInt
A level property as an int, coerced from aNumber/numericString, elsedef. -
getString
-
layers
-
addLayer
-
getLayer
-
elements
The placedGameElements, across all layers; mutable. -
addElement
Adds a placed element to the level. -
lights
-
getTerrain
-
setTerrain
-
getWorld
The streaming/region world backing a "large world" level, or null for a bounded level. When set, the active region'sStreamingTerrainis the authoritative terrain and the bounded#getTerrain()grid is unused. Serialized inline under the "world" key. -
setWorld
-
isLargeWorld
public boolean isLargeWorld()True when this level is backed by a streamingGameWorldof regions rather than a single bounded grid. -
setCamera
public GameLevel setCamera(float eyeX, float eyeY, float eyeZ, float targetX, float targetY, float targetZ) -
setLens
-
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
Builds
Sprites for the 2D / board content of this level and adds them to the scene: every painted tile of each visibleLayer.Kind#TILElayer plus everyGameElementwhose 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 itsSprite#getUserData()is the sourceGameElement(for tiles, the sourceLayer), so an editor can map a picked sprite back to its data.In
Mode#THREE_Dthis is a no-op (3D content is realized byGameSceneViewonce the GPU device exists). InMode#BOARDpositions go throughprojection(board elements store their column/row in x/y), so pass a fittedIsoProjection. -
realizeSprites
-
load
Parses a level from a JSON string.- Throws:
IOException
-
load
Parses a level from a UTF-8 JSON stream and closes it.- Throws:
IOException
-
toJson
Serializes this level to a compact JSON string (round-trips through#load(String)). -
save
Writes this level as UTF-8 JSON to the stream (does not close it).- Throws:
IOException
-