Page 1 of 1

Tiled and Fullscreen for beginners

Posted: Tue Feb 13, 2018 2:19 pm
by franfox
Hello guys! I've been learning Löve for a week to figure out if it could fit with my needs but I've get stuck when I've started to work with Tiled in a game that needs full resolution or simply scale for x2 the window.

I followed this tutorial for the Tiled stuff.

And I'm trying to scale the game with something like this:

Code: Select all

function love.draw()
  do
    local scale = love.graphics.getWidth() / myGameScreenWidth
    local scaleY = love.graphics.getHeight() / myGameScreenHeight
    if scaleY < scale then scale = scaleY end
    love.graphics.scale(scale)
  end
  -- the rest of your love.draw goes here
end
I'm wondering how you guys deal with these topics together. Are you using some lib? What would you recommend to an absolute beginner?

Thanks in advance!

Re: Tiled and Fullscreen for beginners

Posted: Thu Feb 15, 2018 5:04 am
by jojomickymack
I'm confused what you're trying to do - scale a map using sti when you're in fullscreen?

I think you've almost got it in your example there - this is how I did it, it's probably easier to understand what's happening.

Code: Select all

function love.load()
    oldWidth, oldHeight = love.graphics.getWidth(), love.graphics.getHeight()
    love.window.setFullscreen(true) -- swap this with setting whatever window dimensions you want
    newWidth, newHeight = love.graphics.getWidth(), love.graphics.getHeight()
    xScale = newWidth / oldWidth
    yScale = newHeight / oldHeight
    ...
    
function love.draw()
    dx = love.graphics.getWidth() / 2 / xScale
    dy = love.graphics.getHeight() / 2 / yScale
    love.graphics.scale(xScale, yScale)
    map:draw(0, 0, xScale, yScale)
if you swap out the 0, 0 with the dx, dy you can translate the map around. No library (besides sti) necessary unless I misunderstood the question?

Re: Tiled and Fullscreen for beginners

Posted: Thu Feb 15, 2018 3:23 pm
by franfox
Thanks jojomickymack! That's great!

Also I want to know how to scale your game window to a double size. For example if your assets are made for 480x320 but you want to show the window at 960x640

Re: Tiled and Fullscreen for beginners

Posted: Thu Feb 15, 2018 6:34 pm
by jojomickymack
What you want is window.setMode
https://love2d.org/wiki/love.window.setMode

you can set the window to whichever dimensions you want. I'm thinking you want to do a options menu where you can set the window size - just do this in place of where I did the setFullscreen call. Obviously, if you know set the width/height of the window, you don't have to get the window height/width like in the example, you'd do it like this

Code: Select all

oldWidth, oldHeight = love.graphics.getWidth(), love.graphics.getHeight()
desiredWidth, desiredHeight = 960, 640
love.window.setMode(desiredWidth, desiredHeight)
xScale = desiredWidth / oldWidth
yScale = desiredHeight / oldHeight
Maybe there could be different window size options you provide in a menu and you could put this code in a function and have the desiredWidth/height as arguments to the function.

That actually might be a nice bit of reusable code - if you create that, post it up here to share!

Re: Tiled and Fullscreen for beginners

Posted: Fri Feb 16, 2018 4:18 pm
by franfox
This is exactly what I need! Thanks!