rounded rectangle

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
unek
Citizen
Posts: 86
Joined: Fri Oct 12, 2012 8:43 pm
Location: Poland
Contact:

rounded rectangle

Post by unek »

Hello. How can I simply draw semi-transparent rounded rectangle? Most of code snippets I found on forums don't work.

Thanks for help.
DRAW DRAW - online painting app CLICK NUMBERS - cool game with numbers THEME LOVEFRAMES - a collection of my themes HOST FOR FREE - free hosting for online LOVE games STALK PEOPLE - a map of LOVE users
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

Re: rounded rectangle

Post by Nsmurf »

For semi transparency use:

Code: Select all

love.graphics.setColor(255, 255, 255, a)
--draw something
love.graphics.setColor(255, 255, 255, 255)
where a is the transparency from 1 (transparent) to 255 (solid).

for a rounded rectangle, I would just use a image.
OBEY!!!
My Blog
UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: rounded rectangle

Post by kikito »

Nsmurf wrote:for a rounded rectangle, I would just use a image.
Try a polygon. (Also, forum search is your friend :))
When I write def I mean function.
User avatar
unek
Citizen
Posts: 86
Joined: Fri Oct 12, 2012 8:43 pm
Location: Poland
Contact:

Re: rounded rectangle

Post by unek »

kikito wrote:
Nsmurf wrote:for a rounded rectangle, I would just use a image.
Try a polygon. (Also, forum search is your friend :))
The selected attachment does not exist anymore.
DRAW DRAW - online painting app CLICK NUMBERS - cool game with numbers THEME LOVEFRAMES - a collection of my themes HOST FOR FREE - free hosting for online LOVE games STALK PEOPLE - a map of LOVE users
User avatar
Nsmurf
Party member
Posts: 191
Joined: Fri Jul 27, 2012 1:58 am
Location: West coast.

Re: rounded rectangle

Post by Nsmurf »

forums wrote:The selected attachment does not exist anymore.
But it's still good to know about a polygon. How much better/faster is it to draw a polygon as opposed to an image?
OBEY!!!
My Blog
UE0gbWUgd2l0aCB0aGUgd29yZCAnSE1TRycgYXMgdGhlIHN1YmplY3Q=
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: rounded rectangle

Post by Boolsheet »

I made this once. Perhaps you can use it.

Code: Select all

local right = 0
local left = math.pi
local bottom = math.pi * 0.5
local top = math.pi * 1.5

function rwrc(x, y, w, h, r)
	r = r or 15
	love.graphics.rectangle("fill", x, y+r, w, h-r*2)
	love.graphics.rectangle("fill", x+r, y, w-r*2, r)
	love.graphics.rectangle("fill", x+r, y+h-r, w-r*2, r)
	love.graphics.arc("fill", x+r, y+r, r, left, top)
	love.graphics.arc("fill", x + w-r, y+r, r, -bottom, right)
	love.graphics.arc("fill", x + w-r, y + h-r, r, right, bottom)
	love.graphics.arc("fill", x+r, y + h-r, r, bottom, left)
end
You can call it like this rwrc(10, 50, 200, 350, 40).
Shallow indentations.
User avatar
unek
Citizen
Posts: 86
Joined: Fri Oct 12, 2012 8:43 pm
Location: Poland
Contact:

Re: rounded rectangle

Post by unek »

Thanks Boolsheet! That is exactly what I was looking for!
DRAW DRAW - online painting app CLICK NUMBERS - cool game with numbers THEME LOVEFRAMES - a collection of my themes HOST FOR FREE - free hosting for online LOVE games STALK PEOPLE - a map of LOVE users
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: rounded rectangle

Post by kikito »

Omf. I forgot that LÖVE can draw arcs now.

Back in my time, we had to calculate segment coordinates with our bare trigonometrics functions. You youngsters have it very easy nowadays :D.
When I write def I mean function.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: rounded rectangle

Post by Xgoff »

kikito wrote:Back in my time, we had to calculate segment coordinates with our bare trigonometrics functions.
well, you still do if you don't want those extra two lines connecting the center point in line draw mode
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: rounded rectangle

Post by Robin »

Apparently, this is the third time I have to upload these things:
roundbox.love
(631 Bytes) Downloaded 277 times
roundrect.lua
(958 Bytes) Downloaded 317 times
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests