Module ctr.gfx.map
The gfx.map module.
Tile coordinates start at x=0,y=0.
Usage:
local map = require("ctr.gfx.map")
Functions
load (map, tileset, tileWidth, tileHeight) | Load a map from a file. |
Map object
:draw (x, y[, offsetX=0[, offsetY=0[, width=400[, height=240]]]]) | Draw (a part of) the map on the screen. |
:unload () | Unload a map. |
:getSize () | Return the size of a map. |
:getTile (x, y) | Return the value of a tile. |
:setTile (x, y, value) | Set the value of a tile. |
:setSpace (x, y) | Set the space between draw tiles (in pixels). |
Functions
- load (map, tileset, tileWidth, tileHeight)
-
Load a map from a file.
Parameters:
- map
string/table
path to the .map or a 2D table containing tile data (
{ [Y1]={[X1]=tile1, [X2]=tile2}, [Y2]=..., ... }
) - tileset texture containing the tileset
- tileWidth number tile width
- tileHeight number tile height
Returns:
-
map
loaded map object
Or
- nil in case of error
- string error message
- map
string/table
path to the .map or a 2D table containing tile data (
Map object
- :draw (x, y[, offsetX=0[, offsetY=0[, width=400[, height=240]]]])
-
Draw (a part of) the map on the screen.
Parameters:
- x integer X top-left coordinate to draw the map on the screen (pixels)
- y integer Y top-left coordinate to draw the map on the screen (pixels)
- offsetX integer drawn area X start coordinate on the map (pixels) (x=0,y=0 correspond to the first tile top-left corner) (default 0)
- offsetY integer drawn area Y start coordinate on the map (pixels) (default 0)
- width integer width of the drawn area on the map (pixels) (default 400)
- height integer height of the drawn area on the map (pixels) (default 240)
Usage:
-- This will draw on the screen at x=5,y=5 a part of the map. The part is the rectangle on the map starting at x=16,y=16 and width=32,height=48. -- For example, if you use 16x16 pixel tiles, this will draw the tiles from 1,1 (top-left corner of the rectangle) to 2,3 (bottom-right corner). map:draw(5, 5, 16, 16, 32, 48)
- :unload ()
- Unload a map.
- :getSize ()
-
Return the size of a map.
Returns:
- number width of the map, in tiles
- number height of the map, in tiles
- :getTile (x, y)
-
Return the value of a tile.
Parameters:
- x number X position of the tile (in tiles)
- y number Y position of the tile (in tiles)
Returns:
-
number
value of the tile
- :setTile (x, y, value)
-
Set the value of a tile.
Parameters:
- x number X position of the tile (in tiles)
- y number Y position of the tile (in tiles)
- value number new value for the tile
- :setSpace (x, y)
-
Set the space between draw tiles (in pixels).
Parameters:
- x number X space (in pixels)
- y number Y space (in pixels)