love2d在调整窗口时保持长宽比

https://love2d.org/forums/viewtopic.php?t=80435

Draw everything to a canvas, check the aspect ratio of the window

绘制到canvas上面

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
posted on 2026-02-06 10:06  小沙盒工作室  阅读(0)  评论(0)    收藏  举报