Tiled and Fullscreen for beginners

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
franfox
Prole
Posts: 11
Joined: Fri Feb 09, 2018 3:48 pm

Tiled and Fullscreen for beginners

Post 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!
User avatar
jojomickymack
Prole
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: Tiled and Fullscreen for beginners

Post 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?
Attachments
sti_fullscreen001.love
(70.8 KiB) Downloaded 211 times
User avatar
franfox
Prole
Posts: 11
Joined: Fri Feb 09, 2018 3:48 pm

Re: Tiled and Fullscreen for beginners

Post 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
User avatar
jojomickymack
Prole
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: Tiled and Fullscreen for beginners

Post 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!
User avatar
franfox
Prole
Posts: 11
Joined: Fri Feb 09, 2018 3:48 pm

Re: Tiled and Fullscreen for beginners

Post by franfox »

This is exactly what I need! Thanks!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests