Trying to create a rounded rectangle to which I will then turn into a button. (Still learning)
This is my code with the error at the bottom. In run view all I am seeing is an actual rectangle, not a rounded.
I understands the line functions are setting the full for the rounded edges but I’m not entirely sure of why they are set out with the insetpos, sizes and +'s.
function roundRect(x,y,w,h,r)
pushStyle()
insetPos = vec2(x+r,y+r)
insetSize = vec2(w-2*r,h-2*r)
--Copy fill into stroke
local red,green,blue,a = fill()
stroke(red,green,blue,a)
noSmooth()
rectMode(CORNER)
rect(insetPos.x,insetPos.y,insetSize.x,insetSize.y)
if r > 0 then
smooth()
lineCapMode(ROUND)
strokeWidth(r*2)
line(insetPos.x, insetPos.y,
insetPos.x + insetSize.x, insetPos.y)
line(insetPos.x, insetPos.y,
insetPos.x, insetPos.y + insetSize.y)
line(insetPos.x, insetPos.y + insetSize.y,
insetPos.x + insetSize.x, insetPos.y + insetSize.y)
line(insetPos.x + insetSize.x, insetPos.y,
insetPos.x + insetSize.x, insetPos.y + insetSize.y)
end
popStyle()
end
function draw()
roundRect(WIDTH/2, HEIGHT/2, 300, 20, 30)
enderror: [string "-- rounded rec..."]:22: attempt to index global 'insetPos' (a nil value)
If anyone could help I’d greatly appreciate