Skip to content
planer28 edited this page Nov 23, 2018 · 31 revisions

map

map [x=0 y=0] [w=30 h=17] [sx=0 sy=0] [colorkey=-1] [scale=1] [remap=nil]

Parameters:

  • x : The left-most cell to start drawing the map.
  • y : The top-most cell to start drawing the map.
  • w : The amount of cells to draw horizontally from cellx.
  • h : The amount of cells to draw vertically from celly.
  • sx : The x coordinate to draw the map to the screen.
  • sy : The y coordinate to draw the map to the screen.
  • colorkey : The indexed color (0-15) to use as the alpha channel. Not setting this parameter will make the map opaque.
  • scale : Map scaling.
  • remap: function callback called before every tile drawing, you can show/hide tiles on map rendering stage (also, you can remap tile index to make map animation or even flip/rotate): callback [tile [x y] ] -> [tile [flip [rotate] ] ]

Remap:

The map function’s last parameter is a powerful callback function​ for changing the sprites that are drawn while calling map. This remap function can be used to rotate, flip and replace sprites while the game is running. Unlike mset that saves changes to the map, this special function can be used to create animated tiles or replace the tiles completely. Some examples include changing sprites to open doorways, hide sprites used to spawn objects in your game, and even to emit the objects themselves.

Description:

The map is measured in cells, 8x8 blocks which you can place sprites on in the map editor. This function will draw the entire map, or parts of it. The map's cell limit is 240x136.

Example:

--divide the map into rooms
rooms = {}
 for x = 0,240-30,30 do
  for y = 0,136-17,17 do
   table.insert(rooms, {x,y})
  end
 end

--returns the room by index (1-64)
function rget(i)
 return rooms[i][1],rooms[i][2],30,17
end

function TIC()
 cls()
 map(rget(64))
end
Clone this wiki locally