'Background colour in LÖVE
I've set up a config file and I just got started writing a program to set up the title screen for a text-based RPG/simulation game. The background colour doesn't seem to be changing from the default black, which is the issue. I've posted my existing code below. Yes, I'm executing the entire folder that contains the config file and this code.
function love.load()
love.graphics.setBackgroundColor( 255, 255, 255 )
end
function love.update(dt)
end
function
love.graphics.newImage (\LUA txt adventure\Title.png)
end
function love.conf(t)
t.modules.joystick = true -- Enable the joystick module (boolean)
t.modules.audio = false -- Enable the audio module (boolean)
t.modules.keyboard = true -- Enable the keyboard module (boolean)
t.modules.event = true -- Enable the event module (boolean)
t.modules.image = true -- Enable the image module (boolean)t.modules.graphics = true -- Enable the graphics module (boolean)
t.modules.timer = true -- Enable the timer module (boolean)
t.modules.mouse = true -- Enable the mouse module (boolean)
t.modules.sound = false -- Enable the sound module (boolean)
t.modules.thread = true
t.modules.physics = true -- Enable the physics module (boolean)
t.console = false -- Attach a console (boolean, Windows only)
t.title = "Space Trade Sim" -- The title of the window the game is in (string)
t.author = "Magikarp" -- The author of the game (string)
t.window.fullscreen = false -- Enable fullwindow (boolean)
t.window.vsync = false -- Enable vertical sync (boolean)
t.window.fsaa = 0 -- The number of FSAA-buffers (number)
t.window.height = 600 -- The window height (number)
t.window.width = 800 -- The window width (number)
end
Solution 1:[1]
While the question's code is correct before version 11 when this question was asked, the colours are now expressed as a float between 0~1 instead of 0~255 (0.0 == 0.0, 0.5 == 127, 1.0 == 255, etc.). At the time of asking, the arguments passed to setBackgroundColor()
were not the cause of the issue.
The main issue is that any drawing-related function will have no effect if called outside of the love.draw()
function.
To fix this, simply move the code from love.load()
to love.draw()
.
And to address the code already written: I assume that setBackgroundColor()
was being called from love.load
to avoid performance overhead of an extra draw function. However, calling it every frame is not a performance issue on modern hardware, and filling the background and performing lots of other draw calls on every frame is perfectly OK (within reason, doing 10,000 draws per frame is extreme and could likely be optimized).
(DISCLAIMER: I did not reinstall LOVE to test this. I am constructing this answer from information gathered from the other two answers; LOVE documentation; and common sense. I'm 6 years older, dumber, and more jaded at the ripe old age of 23.)
Also gimme my upvotes back you hacks >:(
Solution 2:[2]
love.graphics.setBackgroundColor()
cannot do (255, 255, 255)
. LÖVE (since V 11.0) sets colors a little bit differently, using a range of 0 thru 1 for each component; so, try love.graphics.setBackgroundColor( 1, 1, 1 )
or love.graphics.setBackgroundColor( 255/255, 255/255, 255/255 )
Solution 3:[3]
What @freeve4 wrote is true.
And you can give a table a name and fill it up with what the name suggesting.
Like...
local myBlue = {0.25, 0.25, 0.75, 1} -- Last One means no transparency
function love.draw()
love.graphics.setBackgroundColor(myBlue) -- Use it
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Magikarp |
Solution 2 | |
Solution 3 |