LÖVE 中的背景颜色

Background colour in LÖVE

我已经设置了一个配置文件,我刚刚开始编写一个程序来设置 text-based RPG/simulation 游戏的标题屏幕。 背景颜色似乎没有从默认的黑色改变,这就是问题所在。我已经在下面发布了我现有的代码。是的,我正在执行包含配置文件和这段代码的整个文件夹。

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

love.graphics.setBackgroundColor() 做不到 (255, 255, 255)。 LÖVE(自 V 11.0 起)设置颜色略有不同,每个组件 using a range of 0 thru 1;所以,试试 love.graphics.setBackgroundColor( 1, 1, 1 )love.graphics.setBackgroundColor( 255/255, 255/255, 255/255 )

@freeve4 写的是真的。
你可以给一个 table 一个名字,然后用这个名字的暗示填满它。
喜欢...

local myBlue = {0.25, 0.25, 0.75, 1} -- Last One means no transparency

function love.draw()                                                                                                        
    love.graphics.setBackgroundColor(myBlue) -- Use it
end

虽然在版本 11 之前问这个问题时问题的代码是正确的,但颜色现在表示为 0~1 之间的浮点数而不是 0~255(0.0 == 0.0, 0.5 == 127, 1.0 = = 255 等)。在询问时,传递给 setBackgroundColor() 的参数不是问题的原因。

主要问题是,如果在 love.draw() 函数之外调用,任何 drawing-related 函数都将 无效

要解决此问题,只需将代码从 love.load() 移动到 love.draw()

并解决已经编写的代码:我假设 setBackgroundColor() 是从 love.load 调用的,以避免额外绘制函数的性能开销。然而,在现代硬件上每帧都调用它并不是性能问题,填充背景并在每一帧上执行大量其他绘制调用是完全可以的(在合理范围内,每帧执行 10,000 次绘制是极端的并且可能会被优化)。

(免责声明:我没有重新安装 LOVE 来测试这个。我是根据从其他两个答案收集的信息构建这个答案的;LOVE 文档;和常识。我比我大 6 岁,更笨,更厌倦在 23 岁的高龄。)

也给我点赞支持你的技巧>:(