Class GameLevelImport
Turns a GameLevel -- what the game builder and com.codename1.gaming.level
author -- into a platformer LevelData.
The two describe different things on purpose. A GameLevel is authoring
data for any game: layers of painted tiles and placed elements, positions in
doubles, resolved to sprites or models by a LevelRealizer, optionally
streamed by region through a GameWorld. A LevelData is the input of a
deterministic simulation that a server replays: whole tiles with collision
meaning, 16.16 fixed point, no images and no doubles, so it can be marked
@SharedWithBackend. A common base class would have to hold neither the
sprites nor the doubles, which leaves nothing worth sharing; the connection is
this one-way import instead, done once when a level is loaded.
Tiles come from every Layer.Kind#TILE layer: each painted asset is looked
up in tiles and becomes that Tile character (#, =, H, ...); an
asset missing from the map is decoration and stays empty. Elements become
entries of entities, typed by entities.get(assetId), at the cell their
center is in, with their properties copied over. The types spawn and goal
set the level's spawn and goal instead. Anything unmapped is skipped.
Map<String, Character> tiles = new HashMap<String, Character>();
tiles.put("grass", Character.valueOf('#'));
Map<String, String> entities = new HashMap<String, String>();
entities.put("coin", "coin");
entities.put("start", "spawn");
PlatformWorld world = GameLevelImport.toLevelData(level, tiles, entities).createWorld(seed);
-
Method Summary
-
Method Details
-
toLevelData
public static LevelData toLevelData(GameLevel level, Map<String, Character> tiles, Map<String, String> entities) Converts a level.
Parameters
level: the authored level; its grid size and tile size are kepttiles: asset id toTilecharacterentities: asset id toLevelDataentity type, orspawn/goal
Returns
the level data
-