-
Notifications
You must be signed in to change notification settings - Fork 16
Reference
All Maps properties are accessible (and editable) through the TileMaps object.
console.log(TileMaps)
Object { desert: {…}, hexagonal: {…}, isometric: {…} }
console.log(TileMaps["desert"])
Object { compressionlevel: -1, height: 40, infinite: false, layers: (1) […], nextlayerid: 2, nextobjectid: 1, orientation: "orthogonal", renderorder: "right-down", tiledversion: "1.7.2", tileheight: 32, … }
console.log(TileMaps["desert"].layers.length)
1
console.log(TileMaps["desert"].layers[0])
Object { data: (1600) […], height: 40, id: 1, name: "Ground", opacity: 1, type: "tilelayer", visible: true, width: 40, x: 0, y: 0 }
param {String} mapName Map name.
param {String} [imagePath] Path to the image file(s). Default: "/".
param {Number} [transparentOffset] Maximum difference on RGB channels to apply Tile transparency. Default: 4.
param {Function} [callback] Name of a function to call once map loads.
return {p5.TiledMap}
function preload() {
tmap = loadTiledMap("desert", "data");
}
draw() draws a TiledMap.
- Layer Visible property is respected.
- Opacity is ignored.
- The use of a off-screen graphics buffer is optional.
- Canvas (or the off-screen graphics buffer) IS NOT CLEARED BEFORE.
param {Number} camLeft Left Coordinate.
param {Number} camTop Top Coordinate.
param {Object} [pg] Off-screen graphics buffer.
function draw() {
background(128);
tmap.draw(0, 0);
}
drawLayer() draws a TiledMap Layer.
- Visible property is ignored when drawing individual layers.
- The use of a off-screen graphics buffer is optional. Can be used for extra image editing or if you want to use the layer opacity property (which is ignored when drawing to canvas).
- Canvas (or the off-screen graphics buffer) IS NOT CLEARED BEFORE (that's up to you).
- That means you can draw several layers on a buffer, but the layer opacity will affect all layers drawn before.
param {Number} layer Layer Index.
param {Number} camLeft Left Coordinate.
param {Number} camTop Top Coordinate.
param {Object} [pg] Off-screen graphics buffer.
function draw() {
tmap.drawLayer(0, 0, 0);
}
Define the meaning of draw and drawLayer coordinates. By default, they are camLeft and camTop - the left/top coordinates of the camera, but with setDrawMode(CENTER), they become the coordinates of the camera center.
param {Constant} mode CORNER or CENTER
return {Constant} mode CORNER or CENTER. Default: CORNER.
Define the meaning of draw and drawLayer coordinates. By default, the coordinates are read as pixel position but with setPositionMode("MAP"), they become Tiles Coordinates.
param {String} mode "CANVAS" or "MAP".
return {String} mode "CANVAS" or "MAP". Default: "CANVAS".
param {Number} margin Number of tiles to be draw in excess around Canvas. Default: 2.
return {Number} margin Number of tiles to be draw in excess around Canvas. Default: 2.
Depending on positionMode, returns the Map (Tile) or Canvas (Pixels) coordinates.
return {p5.Vector} Left Top Corner Coordinates
Depending on positionMode, returns the Map (Tile) or Canvas (Pixels) coordinates.
return {p5.Vector} Center Coordinates
Depending on drawMode, returns the camera corner or center coordinates.
Depending on positionMode, returns the Map (Tile) or Canvas (Pixels) coordinates.
Essentially, you get the coordinates of last draw.
return {p5.Vector}
return {p5.Vector} Camera (last used Canvas) Width and Height
Only useful for some pre-draw calculations using Conversion Methods, since Cam size is always the last Canvas used to draw.
param {P5.Vector} (width, height)
param {Number} width
param {Number} height
Maps are stored and accessible in TiledMaps Object. These are helper methods to ease Map and Layer management.
return {String} Map Name
return {Number} Map Version
return {String} Map Orientation
return {Array} P5 Color
return {p5.Vector} Map Width and Height (in number of tiles)
return {p5.Vector} Tile Width and Height (in pixels)
return {Number} Only for Hexagonal Maps
param {Number} layer Layer Index.
return {String} Returns Layer Type ("tilelayer", "imagelayer" or "objectgroup").
param {Number} layer Layer Index.
param {Boolean} visible Visible value.
param {Number} layer Layer Index.
return {Boolean} Returns Layer Visibility.
param {Number} layer Layer Index.
param {Number} opacity Opacity of the Layer (between 0 and 1).
param {Number} layer Layer Index.
return {Number} Opacity of a Layer (between 0 and 1).
param {Number} layer Layer Index.
return {p5.Image} Image of a Image Layer.
param {Number} layer Layer Index.
return {Array} Array of Objects on a Object Layer.
param {Number} layer Layer Index.
return {Array} P5 Color of an Object Layer. Default: Black.
param {Number} layer Layer Index.
return {Array} Data of a Tile Layer.
param {Number} layer Layer Index.
return {Object} Custom Properties of a Layer.
setTileIndex changes a tile index. Remember that:
- x, y and t are Integers.
- 0 is an empty tile.
- The stored tile index is the index presented by Tiled +1.
param {Number} layer Layer Index.
param {Number} x Horizontal Coordinate.
param {Number} y Vertical Coordinate.
param {Number} t Tile Index.
param {Number} layer Layer Index.
param {p5.Vector} v Coordinates.
param {Number} t Tile Index.
getTileIndex return the tile index. Remember that:
- x and y are Integers.
- 0 is an empty tile.
- The stored tile index is the index indicated by Tiled +1.
param {Number} layer Layer Index.
param {Number} x Horizontal Coordinate.
param {Number} y Vertical Coordinate.
return {Number} Tile Index.
param {Number} layer Layer Index.
param {p5.Vector} v Coordinates.
return {Number} Tile Index.
Conversion Methods between the 3 coordinate systems in use: MAP (Tile coordinates), CANVAS (Pixel coordinates) and CAM (relative coordinates of the draw).
param {Number} x Canvas Horizontal Coordinate.
param {Number} y Canvas Vertical Coordinate.
return {p5.Vector} Map Coordinates
param {p5.Vector} v Canvas Coordinates.
return {p5.Vector} Map Coordinates
param {Number} x Map Horizontal Coordinate.
param {Number} y Map Vertical Coordinate.
return {p5.Vector} Canvas Coordinates
param {p5.Vector} v Map Coordinates.
return {p5.Vector} Canvas Coordinates
param {Number} x Cam Horizontal Coordinate.
param {Number} y Cam Vertical Coordinate.
return {p5.Vector} Canvas Coordinates
param {p5.Vector} v Cam Coordinates.
return {p5.Vector} Canvas Coordinates
param {Number} x Canvas Horizontal Coordinate.
param {Number} y Canvas Vertical Coordinate.
return {p5.Vector} Cam Coordinates
param {p5.Vector} v Canvas Coordinates.
return {p5.Vector} Cam Coordinates
param {Number} x Cam Horizontal Coordinate.
param {Number} y Cam Vertical Coordinate.
return {p5.Vector} Map Coordinates
param {p5.Vector} v Cam Coordinates.
return {p5.Vector} Map Coordinates
param {Number} x Map Horizontal Coordinate.
param {Number} y Map Vertical Coordinate.
return {p5.Vector} Cam Coordinates
param {p5.Vector} v Map Coordinates.
return {p5.Vector} Cam Coordinates