Add Tiled maps to your sketch.
(c) Caldas Lopes 2016
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
How to use it:
Read the examples.
Ptmx(PApplet applet, String filename)
File must be in data folder.
Example: Ptmx map = new Ptmx(this, "desert.tmx");
Draw map at position (0, 0), just for a quick test.
void draw(PGraphics pg)
Draw map on a given PGraphics at position (0, 0).
void draw(PVector position)
void draw(float left, float top)
Draw map at position (left, top).
void draw(PGraphics pg, PVector position)
void draw(PGraphics pg, float left, float top)
Draw map on a given PGraphics at position (left, top).
void draw(int layer, PVector position)
void draw(int layer, float left, float top)
Draw a specific layer at position (left, top).
void draw(PGraphics pg, int layer, PVector position)
void draw(PGraphics pg, int layer, float left, float top)
Draw a specific layer on a given PGraphics at position (left, top).
All this methods need a layer index
String getType(int layer)
Return "layer", "imagelayer" or "objectgroup".
boolean getVisible(int layer)
void setVisible(int layer, boolean visible)
Visible property is ignored when drawing individual layers.
PImage getImage(int layer)
Return null if layer is not a image layer or index is out of bounds
StringDict getObjects(int layer)
Return null if layer is not a object layer or index is out of bounds
int getObjectsColor(int layer)
Return black if not defined, layer is not a image layer or index is out of bounds
int getData(int layer)
Return null if layer is not a tile layer or index is out of bounds Attention: Tiled store tiles index as index + 1, so 0 is a "no tile". This is internal data, and looks different than what you get if you use set/getTileIndex.
StringDict getCustomProperties(int layer)
float getOpacity(int layer)
void setOpacity(int layer, float opacity)
Opacity is used when drawing individual layers (and on toImage method).
int getTileIndex(int layer, int x, int y)
void setTileIndex(int layer, int x, int y, int value)
Tile indexes are the same you see on Tiled. -1 for "no tile". Return -2 if coordinates are out of bounds.
void toImage(int layer)
Turn a object or tile layer into a image layer. May be useful if you don't need tile or object info, and want a specific opacity on a layer. Opacity is used when creating the image. The created image is truncated to map limits.
Return dimension as number of tiles
Used in hexagonal maps.
void setCamSize(PVector s)
void setCamSize(int w, int h)
Only useful if you want to do some pre-draw calculations, since size is always the size of the last PGraphics (or window).
void setDrawMargin(int n)
Default 1. Used to draw orthogonal maps. Increase it if tiles are big.
void setDrawMode(int mode)
CORNER or CENTER. Default: CORNER. Affect draw coordinates. Draw position corresponds to left-top corner or graphics/window center.
"CANVAS" or "MAP". Default: "CANVAS". Draw coordinates can be relative to the image created when drawing tiles and objects ("CANVAS"). Think as distance in pixels from the left-top corner. In "MAP" PositionMode, coordinates are relative to tiles, so (5, 4) points to the 5th tile from the left, 4th tile from top. Diferences are notorious and useful when using isometric and hexagonal maps.
Return last draw position. Dependent of DrawMode and PositionMode