Page 1 of 1
Resizing the window causes endless flashing
Posted: Mon Mar 29, 2021 10:39 am
by togFox
Code: Select all
function love.load
void = love.window.setMode(someWidthvalue, someHeightvalue)
end
function love.update
void = love.window.updateMode(newWidthvalue,newHeightvalue)
end
The love.update causes endless flashing as the window redraws. If this is not the correct way to resize a window then is there a better way?
Re: Resizing the window causes endless flashing
Posted: Mon Mar 29, 2021 11:08 am
by GVovkiv
You updating setMode every love.update() event
Why you even need do this?
Call it once when you need it
for example:
Code: Select all
function love.load()
love.window.setMode(100, 200)
end
Re: Resizing the window causes endless flashing
Posted: Mon Mar 29, 2021 12:19 pm
by zorg
Just use the callback that's available:
https://love2d.org/wiki/love.resize
Re: Resizing the window causes endless flashing
Posted: Mon Mar 29, 2021 1:02 pm
by togFox
I wanted the screen to be small in launch (a small main menu) so love.load sets it small.
After a button is clicked, I want to make it larger, but not full screen.
Doing a resize inside love.update seems to be the wrong way to do this.
Re: Resizing the window causes endless flashing
Posted: Mon Mar 29, 2021 3:09 pm
by MrFariator
So, what you're talking about is a simple resolution toggle while the game is running? Simply check for when the specified button/menu item is clicked, and only then change the resolution.
Code: Select all
local resolutionMultiplier = 1
local resolutionMultiplierMax = 4
local baseWindowWidth = 100
local baseWindowHeight = 100
function love.load ()
-- initialize window size to whatever the resolution multiplier is at launch
love.window.setMode(baseWindowWidth * resolutionMultiplier, baseWindowHeight * resolutionMultiplier)
end
function love.update (dt)
-- check if menu item or button has been pressed
if resolutionToggleButtonHasBeenClicked() then
resolutionMultiplier = resolutionMultiplier + 1
if resolutionMultiplier > resolutionMultiplierMax then
resolutionMultiplier = 1
end
-- set the resolution
love.window.updateMode(baseWindowWidth * resolutionMultiplier, baseWindowHeight * resolutionMultiplier)
end
end
How you go about implementing the actual toggle check (the "resolutionToggleButtonHasBeenClicked" function) is up to you. Could simply check if a specific keyboard button has been pressed in love.keypressed callback, or some other manner if you want to do it via a pause or configuration menu.
Re: Resizing the window causes endless flashing
Posted: Mon Mar 29, 2021 9:32 pm
by togFox
Hmmm. So you're suggesting I'm pushing too many parameters on the resize?
I'll try that. Thanks!
Re: Resizing the window causes endless flashing
Posted: Tue Mar 30, 2021 2:29 am
by MrFariator
No? The issue in your original post is that you're updating the window mode every time love.update runs, which causes the window to resize/update every single frame. This is not at all a good idea.
You should only ever mess with the window dimensions when you actually mean it. In practice this often means only do something when the user of your application/game is explicitly pressing or toggling something, or maybe even resizing the window manually by dragging its edges. As such, it has nothing to do with the number of parameters you are passing to love.window.updateMode, but the frequency.
Re: Resizing the window causes endless flashing
Posted: Tue Mar 30, 2021 2:59 am
by togFox
Yes. I see. I need a condition around the update so it resizes just the once. Thanks.