Resizing the window causes endless flashing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
togFox
Party member
Posts: 165
Joined: Sat Jan 30, 2021 9:46 am

Resizing the window causes endless flashing

Post 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?
User avatar
GVovkiv
Prole
Posts: 46
Joined: Fri Jan 15, 2021 7:29 am

Re: Resizing the window causes endless flashing

Post 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
User avatar
zorg
Party member
Posts: 3091
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Resizing the window causes endless flashing

Post by zorg »

Just use the callback that's available: https://love2d.org/wiki/love.resize
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
togFox
Party member
Posts: 165
Joined: Sat Jan 30, 2021 9:46 am

Re: Resizing the window causes endless flashing

Post 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.
MrFariator
Party member
Posts: 243
Joined: Wed Oct 05, 2016 11:53 am

Re: Resizing the window causes endless flashing

Post 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.
togFox
Party member
Posts: 165
Joined: Sat Jan 30, 2021 9:46 am

Re: Resizing the window causes endless flashing

Post by togFox »

Hmmm. So you're suggesting I'm pushing too many parameters on the resize?

I'll try that. Thanks!
MrFariator
Party member
Posts: 243
Joined: Wed Oct 05, 2016 11:53 am

Re: Resizing the window causes endless flashing

Post 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.
togFox
Party member
Posts: 165
Joined: Sat Jan 30, 2021 9:46 am

Re: Resizing the window causes endless flashing

Post by togFox »

Yes. I see. I need a condition around the update so it resizes just the once. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests