-
-
Notifications
You must be signed in to change notification settings - Fork 490
map [x=0 y=0] [w=30 h=17] [sx=0 sy=0] [colorkey=-1] [scale=1] [remap=nil]
- x : The leftmost map cell to be drawn.
- y : The uppermost map cell to be drawn.
- w : The number of cells to draw horizontally.
- h : The number of cells to draw vertically.
- sx : The screen x coordinate where drawing of the map section will start.
- sy : The screen y coordinate where drawing of the map section will start.
- colorkey : The indexed color (0-15) to use for transparency. Not setting this parameter will make the map opaque.
- scale : Map scaling.
- remap: An optional function called before every tile is drawn. Using this callback function you can show or hide tiles, create tile animations or flip/rotate tiles during the map rendering stage:
callback [tile [x y] ] -> [tile [flip [rotate] ] ]
The map consists of cells of 8x8 pixels, each of which can be filled with a sprite using the map editor. The map can be up to 240 cells wide by 136 deep. This function will draw the desired area of the map to a specified screen position. For example, map(5,5,12,10,0,0) will draw a 12x10 section of the map, starting from map co-ordinates (5,5) to screen position (0,0).
The map function’s last parameter is a powerful callback function for changing how map cells (sprites) are drawn when map is called. It can be used to rotate, flip and replace sprites while the game is running. Unlike mset, which saves changes to the map, this special function can be used to create animated tiles or replace them completely. Some examples include changing sprites to open doorways, hiding sprites used to spawn objects in your game and even to emit the objects themselves.
--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
-- title: Remap demo
-- author: AnastasiaDunbar, Lua translation by StinkerB06
--Note that `yourWaterfallTile`, `speed` and `frames` aren't defined here.
--This is up to you. The value of `speed` should be greater than 0 but less than or equal to 1.
gameTicks=0
function remap(tile,x,y)
local outTile,flip,rotate=tile,0,0
if tile==yourWaterfallTile then
outTile=outTile+math.floor(gameTicks*speed)%frames
end
return outTile,flip,rotate --or simply `return outTile`.
end
function TIC()
cls()
map(0,0,30,17,0,0,-1,1,remap) --The `remap()` function is used here.
gameTicks=gameTicks+1
end
TIC-80 tiny computer https://tic80.com | Twitter | Telegram | Terms
Built-in Editors
Console
Platform
RAM & VRAM | Display | Palette | Bits per Pixel (BPP) |
.tic
Format | Supported Languages
Other
Tutorials | Code Snippets | Libraries | External Tools | FFT
API
- BDR (0.90)
- BOOT (1.0)
- MENU
- OVR (deprecated)
- SCN (deprecated)
- TIC
- btn & btnp
- circ & circb
- clip
- cls
- elli & ellib (0.90)
- exit
- fget & fset (0.80)
- font
- key & keyp
- line
- map
- memcpy & memset
- mget & mset
- mouse
- music
- peek, peek4
- peek1, peek2 (1.0)
- pix
- pmem
- poke, poke4
- poke1, poke2 (1.0)
- rect & rectb
- reset
- sfx
- spr
- sync
- ttri (1.0)
- time
- trace
- tri & trib (0.90)
- tstamp (0.80)
- vbank (1.0)