Difference between revisions of "love.graphics.setBackgroundColor"

m (Changed text at top to notice, due to it being a recent but major change.)
m
 
(6 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
{{notice|In versions prior to [[11.0]], color component values were within the range of 0 to 255 instead of 0 to 1.}}
 
{{notice|In versions prior to [[11.0]], color component values were within the range of 0 to 255 instead of 0 to 1.}}
 
== Function ==
 
== Function ==
=== Synopsis ===
 
<source lang="lua">
 
love.graphics.setBackgroundColor( red, green, blue )
 
</source>
 
=== Arguments ===
 
{{param|number|red|The red component (0-1).}}
 
{{param|number|green|The green component (0-1).}}
 
{{param|number|blue|The blue component (0-1).}}
 
=== Returns ===
 
Nothing.
 
=== Example ===
 
<source lang="lua">
 
function love.draw()
 
    -- Set Background Color to #1b8724 (27, 135, 36)
 
    -- Note: Remember that Love uses 0-1 and not 0-255
 
    red = 27/255
 
    green = 135/255
 
    blue = 36/255
 
    love.setBackgroundColor( red, green, blue)
 
end
 
</source>
 
 
== Function ==
 
{{newin|[[0.8.0]]|080|type=variant}}
 
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 35: Line 11:
 
{{param|number|green|The green component (0-1).}}
 
{{param|number|green|The green component (0-1).}}
 
{{param|number|blue|The blue component (0-1).}}
 
{{param|number|blue|The blue component (0-1).}}
{{param|number|alpha|The alpha component (0-1).}}
+
{{New feature|0.8.0|
 +
{{param|number|alpha (1)|The alpha component (0-1).}}
 +
|080}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
=== Example ===
 
<source lang="lua">
 
function love.draw()
 
    -- Set Background Color to #731b87 (115, 27, 135) with an alpha of 50%
 
    -- Note: Remember that Love uses 0-1 and not 0-255
 
    red = 115/255
 
    green = 27/255
 
    blue = 135/255
 
    alpha = 50/100
 
    love.setBackgroundColor( red, green, blue, alpha)
 
end
 
</source>
 
  
 
== Function ==
 
== Function ==
Line 61: Line 27:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
=== Example ===
 
<source lang="lua">
 
function love.draw()
 
    -- Set Background Color to #1b8724 (27, 135, 36)
 
    -- Note: Remember that Love uses 0-1 and not 0-255
 
    red = 27/255
 
    green = 135/255
 
    blue = 36/255
 
    color = { red, green, blue}
 
    love.setBackgroundColor( color)
 
end
 
</source>
 
  
 
== Function ==
 
== Function ==
Line 84: Line 38:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
=== Example ===
+
 
 +
== Examples ==
 
<source lang="lua">
 
<source lang="lua">
 +
-- set background color to #84C1EE (132, 193, 238)
 +
local r, g, b = love.math.colorFromBytes(132, 193, 238)
 +
love.graphics.setBackgroundColor(r, g, b)
 +
 +
 
function love.draw()
 
function love.draw()
    -- Set Background Color to #731b87 (115, 27, 135) with an alpha of 50%
+
-- draw any geometry:
    -- Note: Remember that Love uses 0-1 and not 0-255
+
love.graphics.setColor(1,1,1)
    red = 115/255
+
love.graphics.circle('fill', 400, 300, 250)
    green = 27/255
+
love.graphics.setColor(0,0,0)
    blue = 135/255
+
love.graphics.circle('line', 400, 300, 250)
    alpha = 50/100
 
    color = { red, green, blue, alpha}
 
    love.setBackgroundColor( color)
 
 
end
 
end
 
</source>
 
</source>
Line 100: Line 57:
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]
 +
* [[love.graphics.clear]]
 
* [[love.graphics.getBackgroundColor]]
 
* [[love.graphics.getBackgroundColor]]
 +
* [[love.run]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Sets the background color.}}
 
{{#set:Description=Sets the background color.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
{{#set:Sub-Category=State}}
 
{{#set:Sub-Category=State}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.graphics.setBackgroundColor}}
 
{{i18n|love.graphics.setBackgroundColor}}

Latest revision as of 18:32, 18 February 2024

Sets the background color.

O.png In versions prior to 11.0, color component values were within the range of 0 to 255 instead of 0 to 1.  


Function

Synopsis

love.graphics.setBackgroundColor( red, green, blue, alpha )

Arguments

number red
The red component (0-1).
number green
The green component (0-1).
number blue
The blue component (0-1).
Available since LÖVE 0.8.0
number alpha (1)
The alpha component (0-1).

Returns

Nothing.

Function

Available since LÖVE 0.7.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.setBackgroundColor( rgb )

Arguments

table rgb
A numerical indexed table with the red, green and blue values as numbers.

Returns

Nothing.

Function

Available since LÖVE 0.8.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.setBackgroundColor( rgba )

Arguments

table rgba
A numerical indexed table with the red, green, blue and alpha values as numbers.

Returns

Nothing.

Examples

-- set background color to #84C1EE (132, 193, 238)
local r, g, b = love.math.colorFromBytes(132, 193, 238)
love.graphics.setBackgroundColor(r, g, b)


function love.draw()
	-- draw any geometry:
	love.graphics.setColor(1,1,1)
	love.graphics.circle('fill', 400, 300, 250)
	love.graphics.setColor(0,0,0)
	love.graphics.circle('line', 400, 300, 250)
end

See Also



Other Languages