I'd like to add minimum limits on the amount a Love2D window can be resized (e.g. shrunken so as not to obscure objects displayed in the viewport).
Does anyone know if there is a way to set such constraints on a Love2D resizable window?
Thanks
Is there a way to program constraints for resizable windows?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Citizen
- Posts: 55
- Joined: Sat Dec 03, 2022 7:52 pm
Re: Is there a way to program constraints for resizable windows?
Like this?SugarRayLua wrote: ↑Mon Oct 23, 2023 6:39 am I'd like to add minimum limits on the amount a Love2D window can be resized (e.g. shrunken so as not to obscure objects displayed in the viewport).
Does anyone know if there is a way to set such constraints on a Love2D resizable window?
Thanks
https://love2d.org/wiki/love.graphics.scale
Code: Select all
function love.load ()
-- if your code was optimized for fullHD:
window = {translateX = 40, translateY = 40, scale = 2, width = 1920, height = 1080}
width, height = love.graphics.getDimensions ()
love.window.setMode (width, height, {resizable=true, borderless=false})
resize (width, height) -- update new translation and scale
end
function love.update (dt)
-- mouse position with applied translate and scale:
local mx = math.floor ((love.mouse.getX()-window.translateX)/window.scale+0.5)
local my = math.floor ((love.mouse.getY()-window.translateY)/window.scale+0.5)
-- your code here, use mx and my as mouse X and Y positions
end
function love.draw ()
-- first translate, then scale
love.graphics.translate (window.translateX, window.translateY)
love.graphics.scale (window.scale)
-- your graphics code here, optimized for fullHD
love.graphics.rectangle('line', 0, 0, 1920, 1080)
end
function resize (w, h) -- update new translation and scale:
local w1, h1 = window.width, window.height -- target rendering resolution
local scale = math.min (w/w1, h/h1)
window.translateX, window.translateY, window.scale = (w-w1*scale)/2, (h-h1*scale)/2, scale
end
function love.resize (w, h)
resize (w, h) -- update new translation and scale
end
Re: Is there a way to program constraints for resizable windows?
You can check the window dimensions in love.update and enforce minimum window size by resizing.SugarRayLua wrote: ↑Mon Oct 23, 2023 6:39 am I'd like to add minimum limits on the amount a Love2D window can be resized (e.g. shrunken so as not to obscure objects displayed in the viewport).
Does anyone know if there is a way to set such constraints on a Love2D resizable window?
Thanks
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Is there a way to program constraints for resizable windows?
love.conf and love.window.updateMode have minimum window size parameters you can set.
-
- Citizen
- Posts: 55
- Joined: Sat Dec 03, 2022 7:52 pm
Re: Is there a way to program constraints for resizable windows?
Thanks, Everyone-- I'll try those suggestion!
Who is online
Users browsing this forum: Google [Bot] and 2 guests