Personally, I draw everything that is a part of the game itself to a canvas, then scale that, leaving the mobile-specific bits out to be drawn and updated relative to the device, that way they are not scaled with everything else. Not exactly a catch-all solution (at least, not the way I have it set up), and it works really well for small resolution projects, as it can help maintain pixel integrity, but for other things it could probably point you in the right direction.
For reference, this was a setup on a recent project (not elegant, but it worked) :
Code: Select all
-- Draw
function love.draw()
lg.setCanvas(canvas)
lg.clear()
lg.rectangle("fill", 0, 0, canvas:getWidth(), canvas:getHeight())
drawScene()
--Fade Overlay
color(fadec, fade[1])
lg.rectangle("fill", 0, 0, canvas:getWidth(), canvas:getHeight())
lg.setCanvas()
canvasScale = {1, w = lg.getWidth() / canvas:getWidth(), h = lg.getHeight() / canvas:getHeight()}
-- Draw canvas scaled according to setting
if not allowStretching then
canvasScale[1] = math.min(canvasScale.w, canvasScale.h)
if maintainAspectRatio then
canvasScale[1] = math.floor(canvasScale[1])
end
lg.draw(canvas, (lg.getWidth() / 2) - ((canvas:getWidth() * canvasScale[1]) / 2), (lg.getHeight() / 2) - ((canvas:getHeight() * canvasScale[1]) / 2), 0, canvasScale[1])
else
lg.push()
lg.draw(canvas, 0, 0, 0, canvasScale.w, canvasScale.h)
lg.pop()
end
if isMobile then
-- Draw mobile UI
lg.draw(dpad, 64, lg.getHeight() - 64 - dpad:getHeight())
lg.draw(actions, lg.getWidth() - 64 - actions:getWidth(), lg.getHeight() - 64 - actions:getHeight())
end
end
(It even looks like I have fragments of other code I hadn't cleaned up in there... Whoops...)
If you want to see what that looks like in action, you're more than welcome to open the project's (patently messy) code, run it on a mobile device, or run it with a "-mobile" command line argument to see how the screen and UI react to different resolutions.
Project is here