Lovely-Windows
Posted: Mon Jun 05, 2017 4:24 pm
Hi, im excited to share with you lovely people my very first module/library for Love2D called Lovely-Windows.
See the github repo for more info
See the github repo for more info
Code: Select all
local width = {
f1 = 1024,
f2 = 720,
}
local height = {
f1 = 720,
f2 = 640
}
Code: Select all
local table = {
f1 = {1024, 720 },
f2 = {720, 640 }
}
Code: Select all
-- At the top
local currentMode = "[default mode here]"
-- ...
function WINDOW.switch(key)
if key ~= currentMode then
love.window.setMode(WIDTH[key], HEIGHT[key])
WINDOW.initialize(_window.gameWidth,_window.gameHeight)
currentMode = key
end
end
Thanks for the feedback, as of now, the first problem/issue you presented has already been fixed and changed, also thanks to Positive07 for specifying also.MrFariator wrote: ↑Mon Jun 05, 2017 5:25 pm It's a pretty simple and straight forward library, but there are a few things I could comment on.
Firstly, passing a list of window sizes like this......as opposed to...Code: Select all
local width = { f1 = 1024, f2 = 720, } local height = { f1 = 720, f2 = 640 }
...feels like you'd have better success reinforcing the "tables should match" recommendation you have in the sample code. Even that recommendation is a bit of a misnomer, because unless the width and height tables match in terms of their keys, you will be nil values in WINDOW.switch. You could add small exception handling to WINDOW.addInputTable in order to avoid such troubles.Code: Select all
local table = { f1 = {1024, 720 }, f2 = {720, 640 } }
Additionally, looking at your WINDOW.update and WINDOW.switch methods, you could just remove the update method altogether and change the switch method like the following:
This would allow you to forego the timer based approach to resolving an user holding a button down and thus having their resolution changed rapidly. Of course, you could still keep the timer to avoid rapid-fire window size switching if necessary (user could be pressing F1 and F2 very rapidly).Code: Select all
-- At the top local currentMode = "[default mode here]" -- ... function WINDOW.switch(key) if key ~= currentMode then love.window.setMode(WIDTH[key], HEIGHT[key]) WINDOW.initialize(_window.gameWidth,_window.gameHeight) currentMode = key end end
Also of note is your use of love.window.setMode. I might be remembering things wrong or think of outdated stuff from few LÖVE versions ago, but unless you pass the flags table as the third parameter, changes to the window's option flags won't persist. This could cause issues such as vsync turning on when it could be against the user's (and developer's) wishes.