Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class TiledImport
- Object
- TiledImport
Turns a map drawn in the Tiled editor into a level, so levels can be made in the tool most 2D games already use.
Export the map as JSON (.tmj, or .json) with embedded tilesets and
CSV layer data (Tiled’s defaults for JSON). Then:
import com.codename1.gaming.platformer.*;
import com.codename1.io.Util;
String tmjText = Util.readToString(Display.getInstance().getResourceAsStream(null, "/map.tmj"));
LevelData level = LevelData.parse(TiledImport.toLevelJson(tmjText));What is read:
- The collision layer: the tile layer named
collision, or else the first tile layer. A tile’s kind comes from acollisionproperty on the tile in its tileset:solid,oneway,slope_up,slope_down,ladder,hazard,waterorempty. Tiles without one are solid. - Other tile layers are art only and are listed under
"layers", rows of global tile ids, for a game’s own renderer to draw. - Objects, from every object layer. An object’s class (Tiled 1.9+) or
type names what it is:
spawn,goal(its rectangle in whole tiles), or any entity typeLevelDataor the game’sEntityFactoryknows –coin,enemy,crate,doorand the rest. Its custom properties become the entity’s fields, so an enemy’sbrainor a door’skeyare set in Tiled. - Map properties become the level’s header:
name,world,lives,players,health,par, andabilitiesas a comma-separated list.
Not supported, and reported as an error rather than read wrongly: infinite maps, base64 or compressed layer data and external tilesets.
Methods
public static String toLevelJson(String tmj) | Converts a Tiled JSON map to level JSON. |
Inherited methods
Method details
toLevelJson
public static String toLevelJson(String tmj)Converts a Tiled JSON map to level JSON.
Parameters
tmjString- the map, as Tiled writes it
Returns
the level JSON, for
LevelData#parse(String)Throws
IllegalArgumentException- when the map uses something not supported