PICO-8 grid rajzolás v1.0
2026., április 8.
-- grid initialization in _init
function _init()
grid_timer = 0
-- increase this to make the drawing faster
-- (e.g., 1 = one sprite/frame, 16 = one full line/frame if width is 16)
fill_rate = 8
grid_done = false
end
function _update()
-- only increment timer if the grid animation is not yet finished
if not grid_done then
grid_timer += fill_rate
end
end
function _draw()
cls(0) -- clear screen to black
-- call the grid drawing function
-- parameters:
-- x:8, y:8 -> starting top-left pixel coordinates
-- dx:14, dy:14 -> grid dimensions (14x14 sprites)
draw_retro_grid(8, 8, 14, 14)
end
---------------------------------------------------
-- retro grid drawing function
---------------------------------------------------
-- x,y: top-left corner of the entire grid
-- dx,dy: number of columns and rows
---------------------------------------------------
function draw_retro_grid(x, y, dx, dy)
local spr_s = 8 -- standard pico-8 sprite size (8x8 pixels)
local total_sprites = dx * dy
-- current number of sprites to display based on the timer
local current_count = flr(grid_timer)
-- cap the count at the maximum number of sprites
if current_count >= total_sprites then
current_count = total_sprites
grid_done = true
end
-- iterate through all sprites that should be visible currently
for i = 0, current_count - 1 do
-- calculate logical row and column
-- using 'i' ensures we follow a specific sequence
local current_row = flr(i / dx)
local current_col = i % dx
-- calculate screen coordinates:
-- (dx - 1 - current_col) starts drawing from right to left
local spr_x = x + ((dx - 1 - current_col) * spr_s)
-- (dy - 1 - current_row) starts drawing from bottom to top
local spr_y = y + ((dy - 1 - current_row) * spr_s)
-- draw sprite #0 from the sprite sheet
spr(0, spr_x, spr_y)
end
end