push - a resolution-handling library

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kuzika
Prole
Posts: 16
Joined: Tue Apr 21, 2020 3:58 pm

Re: push - a resolution-handling library

Post 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.
"kuzika" literally means "to burry"
nequals30
Prole
Posts: 9
Joined: Sun Sep 22, 2019 5:54 pm

Re: push - a resolution-handling library

Post 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.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: push - a resolution-handling library

Post 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.
nequals30
Prole
Posts: 9
Joined: Sun Sep 22, 2019 5:54 pm

Re: push - a resolution-handling library

Post 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.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: push - a resolution-handling library

Post 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.
User avatar
SoupremeChickn
Prole
Posts: 1
Joined: Wed Mar 15, 2023 2:51 am

Re: push - a resolution-handling library

Post by SoupremeChickn »

Thanks for making this, this is really helpful.
Sometimes my brain just





doesn't
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: push - a resolution-handling library

Post 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().
User avatar
GVovkiv
Party member
Posts: 686
Joined: Fri Jan 15, 2021 7:29 am

Re: push - a resolution-handling library

Post 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!
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: push - a resolution-handling library

Post 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.
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: push - a resolution-handling library

Post 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().
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests