New in PICO-8 0.2.0.
- Draws a textured line between two points, sampling the map for texture data.
- x0
-
- The x coordinate of the start of the line.
- y0
-
- The y coordinate of the start of the line.
- x1
-
- The x coordinate of the end of the line.
- y1
-
- The y coordinate of the end of the line.
- mx
-
- The x coordinate to begin sampling the map, expressed in (fractional) map tiles.
- my
-
- The y coordinate to begin sampling the map, expressed in (fractional) map tiles.
- mdx
-
- The amount to add to mx after each pixel is drawn, expressed in (fractional) map tiles. Default is 1/8 (move right one map pixel).
- mdy
-
- The amount to add to mx after each pixel is drawn, expressed in (fractional) map tiles. Default is 0 (a horizontal line).
The tline()
function draws a line while sampling colors from the map to provide a texture for the line. The mx and my parameters are similar to u,v coordinates used in 3D texture mapping, with the exception that they are expressed in units of map tiles. For example, a coordinate of 4.5,10 would sample from the pixel at 4.5*8,10*8 = 36,80 in the map.
The mdx and mdy parameters are effectively the slope of the line being sampled in the map. They can be fractional, they can be negative, and they can be 0. If both are 0, the whole line will sample from the same pixel on the map.
The map coordinates (mx, my) are masked by values calculated by subtracting 0x0.0001 from the values at address 0x5f38 and 0x5f39. In simpler terms, this means you can loop a section of the map by poking the width and height you want to loop within, as long as they are powers of 2 (2,4,8,16..)
For example, to loop every 8 tiles horizontally, and every 4 tiles vertically:
poke(0x5f38, 8)
poke(0x5f39, 4)
The default values of (0,0) gives a mask of 0xff.ffff causing the samples to loop every 256 tiles.
To choose the offset where the loop starts from (in tiles), use addresses 0x5f3a and 0x5f3b:
poke(0x5f3a, offset_x)
poke(0x5f3b, offset_y)
Examples[]
-- draw 20 textured lines in random locations,
-- sampling from the first pixel row of the map
for x=1,20 do
tline(rnd(128), rnd(128), rnd(128), rnd(128))
end
-- draw 20 textured lines in random locations,
-- sampling from the tenth pixel column of the map
for x=1,20 do
tline(rnd(128), rnd(128), rnd(128), rnd(128), 10/8, 0, 0, 1/8)
end