Hello all. For a game I’m working on I need to draw “blocked” zones (a rect with the lines going across it, pretty straightforward)
I came up with this solution:
-- Use this function to perform your initial setup
function setup()
parameter.watch("1/DeltaTime")
blockedZones = {
{x1 = 0, y1 = 0, x2 = 200, y2 = 400},
{x1 = 210, y1 = 300, x2 = WIDTH - 200, y2 = HEIGHT - 300},
{x1 = WIDTH - 150, y1 = HEIGHT - 200, x2 = WIDTH, y2 = HEIGHT}
}
end
-- This function gets called once every frame
function draw()
background(255)
-- Do your drawing here
for i, blockedZone in ipairs(blockedZones) do
stroke(145, 145, 145, 255) strokeWidth(2)
fill(145, 145, 145, 71) rectMode(CORNERS)
rect(blockedZone.x1 - 2, blockedZone.y1 - 2, blockedZone.x2 + 4, blockedZone.y2 + 4)
local wScale = (blockedZone.x2 - blockedZone.x1) / (blockedZone.y2 - blockedZone.y1)
local h = (blockedZone.y2 - blockedZone.y1) / 20
local w = h * wScale
local numStripes = (blockedZone.x2 - blockedZone.x1) / w
for stripe = 1, numStripes do
local x1, y1, x2, y2
x1 = blockedZone.x1 + (w * (stripe - 1))
y2 = blockedZone.y2 - (h * (stripe - 1))
x2 = x1 + w
y1 = y2 - h
line(blockedZone.x1, y1, x2, blockedZone.y2)
line(x1, blockedZone.y1, blockedZone.x2, y2)
end
end
end
But it eats up the FPS, especially with multiple on the screen at once. I was wondering if it is possible to do something like this with a shader, similar to the brick shader, and if that would be more efficient.