Page 8 of 9

Re: push - a resolution-handling library

Posted: Thu Apr 30, 2020 10:28 am
by kuzika
Ok. That makes sense. Thanks I’ll first remove the translation and see how the camera works. If I get any trouble I’ll start a new thread.

Re: push - a resolution-handling library

Posted: Sat Dec 26, 2020 3:51 am
by nequals30
I've been trying to figure out a major problem I've been having with this library -- when the game dimensions are a different aspect ratio than the screen dimensions, all canvases are drawn shifted relative to what they should be.

After spending a lot of time trying to track it down, I noticed that this only happens when the canvases are drawn in update (it works fine if the canvases are drawn in load).

Here's an example I made which draws a 1280x720 blue rectangle over a 1280x720 game (when the screen is 1500x720).

The conf.lua

Code: Select all

function love.conf(t)
	t.window.width = 1500
	t.window.height = 720
end
The main.lua:

Code: Select all

push = require("push")

local gameWidth, gameHeight = 1280,720

local windowWidth, windowHeight = love.window.getMode()
push:setupScreen(gameWidth,gameHeight,windowWidth,windowHeight,{fullscreen=false})

function love.update(dt)
	thisCanvas = love.graphics.newCanvas(1280,720)
	love.graphics.setCanvas(thisCanvas)
	love.graphics.clear()

	love.graphics.setColor(0,1,1,1)
	love.graphics.rectangle('fill',0,0,1280,720)
	love.graphics.setColor(1,1,1,1)

	love.graphics.setCanvas()
end

function love.draw()
	push:start()

	love.graphics.rectangle('line',1,1,1280,720)
	love.graphics.draw(thisCanvas,0,0)

	push:finish()
end

The canvas (blue) appears shifted right relative to where it should be by 110px (which is the same as how much the game is shifted relative to the screen, but this is an extra 110px on top of that).

I don't see the same issue if the code inside of love.update() gets run inside of love.load(). I'm not trying to draw a canvas on every iteration of the game, but occasionally things inside of love.update will trigger new canvases to be drawn.

Re: push - a resolution-handling library

Posted: Sat Dec 26, 2020 12:26 pm
by pgimeno
push is not preserving the user transform. As a workaround, you can use love.graphics.origin() at the beginning of your love.update.

Note you don't need to create a canvas on every update. You can move the creation line to love.load, and leave the rest in love.update.

Re: push - a resolution-handling library

Posted: Sat Dec 26, 2020 5:03 pm
by nequals30
love.graphics.origin() worked perfectly! Thanks so much for the help, that issue has been bugging me for ages.

My canvas creation and drawing only gets called once (e.g. when a UI element such as the game map is created), but it happens in love.update() because it might get triggered from there (e.g. loading a game).

Push not preserving the user transform -- is this a bug? It's not the functionality I would have expected. Should I report an issue on the Github? I see this one which might be the same question.

Re: push - a resolution-handling library

Posted: Sat Dec 26, 2020 10:53 pm
by pgimeno
I would call it a bug, but Ulydev might have a different opinion. Best is to report it to the author to at least let him know so he can decide. The issue you linked doesn't seem related.

Re: push - a resolution-handling library

Posted: Sat Mar 18, 2023 12:10 am
by SoupremeChickn
Thanks for making this, this is really helpful.

Re: push - a resolution-handling library

Posted: Sat Mar 18, 2023 5:24 pm
by dusoft
nequals30 wrote: Sat Dec 26, 2020 5:03 pm
My canvas creation and drawing only gets called once (e.g. when a UI element such as the game map is created), but it happens in love.update() because it might get triggered from there (e.g. loading a game).
The point was that love.update() gets called repeatedly and often (dt) and any resource heavy operations (canvas creation, fonts, sounds etc.) should be moved out, e.g. into love.load().

Re: push - a resolution-handling library

Posted: Sat Mar 18, 2023 6:13 pm
by GVovkiv
dusoft wrote: Sat Mar 18, 2023 5:24 pm The point was that love.update() gets called repeatedly and often (dt) and any resource heavy operations (canvas creation, fonts, sounds etc.) should be moved out, e.g. into love.load().
Well, after 3 years finally someone answered!

Re: push - a resolution-handling library

Posted: Sat Mar 18, 2023 9:59 pm
by pgimeno
It was already answered actually. And dusoft's answer misses the point: sometimes you have to load resources when the game is already running (e.g. loading a new level); love.load() won't help with that.

Re: push - a resolution-handling library

Posted: Sun Mar 19, 2023 6:20 am
by dusoft
pgimeno wrote: Sat Mar 18, 2023 9:59 pm It was already answered actually. And dusoft's answer misses the point: sometimes you have to load resources when the game is already running (e.g. loading a new level); love.load() won't help with that.
Indeed, but this is what scenes are for. You should still refrain from repeatedly creating/loading resource in love.update().