3

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
Magikarp
  • 171
  • 1
  • 11
  • 1
    Which version of the framework are you using? – legends2k May 04 '16 at 02:46
  • 1
    I'm using version 0.9.2 of LÖVE, @legends2k. – Magikarp May 04 '16 at 02:57
  • 1
    I tried it on 0.10.1 with a `test` folder having a `main.lua` containing only `function love.load() love.graphics.setBackgroundColor(255, 255, 0) end` and it clears the screen with yellow. According to [`love.run`'s documentation](http://love2d.org/wiki/love.run), if you set the background colour correctly, the clearing should be done automatically for you; check if you're setting it correctly. – legends2k May 04 '16 at 02:59
  • 1
    @legends2k I'm not sure what I did, but I got it working, it must have been the name of LUA file or the version of LOVE, I updated both and now it works, thank you for the help. – Magikarp May 04 '16 at 03:41

3 Answers3

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 )

freeve4h
  • 75
  • 1
  • 7
  • 1
    In the time since I asked the question, I've become experienced with Python, JS, GDscript, and Lua and now I'm much more skilled in general. It probably wouldn't be an issue for me now that I have a more complete view of fundamental programming concepts and structuring. Also, 11.0 wouldn't be released for another two years when this was posted. Nonetheless, thanks for the response lmao (I'd suggest explaining floats, you don't explain what "0 thru 1" means and n/255 might seem confusing to new programmers. As per the version I was using, 0~255 would've been correct.) – Magikarp May 28 '22 at 08:58
2

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
koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15
  • 1
    Thanks for the (8 years belated) answer lol. The latest version at the time of that the question was asked is before v11.0 when colors were changed from int:0~255 to float:0~1. Furthermore, you don't specify that using `setBackgroundColor()` in `love.load` instead of `love.draw` is the issue. – Magikarp May 28 '22 at 09:07
2

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 >:(

Magikarp
  • 171
  • 1
  • 11