Maintain Aspect Ratio When Resizing Window?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 22
- Joined: Sat Jun 01, 2013 4:40 am
Maintain Aspect Ratio When Resizing Window?
I want to be able to keep the original aspect ratio of my project with a window that is resizeable.
TLFres seems really outdated and I can't get it to work. Is there any quick (or built-in) solution to this?
Re: Maintain Aspect Ratio When Resizing Window?
Draw everything to a canvas, check the aspect ratio of the window (local ratio = love.graphics.getWidth()/love.graphics.getHeight(); if ratio < 16/9 then) and calculate the offsett you need to draw the canvas to (offsetX = (love.graphics.getWidth() - love.graphics.getHeight()/9*16)/2; offsetY = 0) and do the same thing for Y (elseif ratio > 16/9 then offsetY = (love.graphics.getHeight() - love.graphics.getWidth()/16*9)/2; offsetX = 0 end). Then calculate the scaling for your canvas (local scale = ratio < 16/9 and love.graphics.getHeight()/(canvas_height) or love.graphics.getWidth()/(canvas_width); love.graphics.draw(canvas, offsetX, offsetY, 0, scale, scale)). This code has not been thoroughly tested.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Who is online
Users browsing this forum: Bing [Bot] and 5 guests