Page 1 of 9

push - a resolution-handling library

Posted: Sun Aug 16, 2015 8:47 pm
by Ulydev
So, for the last few days, I've been struggling with handling different screen resolutions.

This said, I decided to upload this (very) simple library I'm actually using for my current game. I hope it helps someone ! :)



push

push is a simple resolution-handling library.

It allows you to set your game a fixed resolution and adapt it to different window sizes.

Code: Select all

local push = require "push"

push:setupScreen(1280, 720, 800, 600, false) --game resolution, window resolution, fullscreen

function love.draw()
  push:apply("start")

  --draw here

  push:apply("end")
end
Image

push repo :
https://github.com/Ulydev/push

Re: [lib] push, a res-handling library

Posted: Sun Aug 16, 2015 10:10 pm
by bartbes
Could you elaborate a bit? What does this take care off? I assume it scales, but does it also take care of aspect ratio, for instance?

Something that also confuses me is what apply(1) and apply(2) do, your github page seems to indicate 1 and 2 are magic constants meaning "start" and "end", but why not just have two functions, or apply("start") and apply("end")?

Re: [lib] push, a res-handling library

Posted: Sun Aug 16, 2015 10:27 pm
by alberto_lara
Could you elaborate a bit? What does this take care off? I assume it scales
I was thinking the same, it would be really nice if this library take care of scaling, aspect ratio and, why not, viewport coordinates (0 to 1 to represent screen dimensions).

Re: [lib] push, a res-handling library

Posted: Mon Aug 17, 2015 12:10 am
by Ulydev
Sorry if I haven't explained it correctly. push scales your game to a target window resolution and corrects the ratio by leaving empty spaces (black bars) on the sides when needed.
Something that also confuses me is what apply(1) and apply(2) do, your github page seems to indicate 1 and 2 are magic constants meaning "start" and "end", but why not just have two functions, or apply("start") and apply("end")?
apply(1) and apply(2) simply applies the scaling and translating operations. It's like push and pop, you have to call them before and after your drawing logic.
And you're right, these numbers may seem confusing. I'll change that. :awesome:

As for the coordinates, you just have to use your fixed game resolution as normally. So, for instance, if you'd like to make a pixel art game, you set your game width and height to 320x200 (or anything) and make your game as if it was targeted for 320x200 screens. push will then scale the game to the screen resolution, center it and add black bars around it.
viewport coordinates (0 to 1 to represent screen dimensions)
I didn't get this, could you explain a bit ? That might be interesting to implement :)

Re: push, a res-handling library

Posted: Mon Aug 17, 2015 11:22 am
by bartbes
Does it also deal with the mouse position?

Re: push, a res-handling library

Posted: Mon Aug 17, 2015 12:36 pm
by Ulydev
Oh, it actually doesn't. I might add it indeed.

Re: push, a res-handling library

Posted: Mon Aug 17, 2015 2:00 pm
by davisdude
Ulydev wrote:
viewport coordinates (0 to 1 to represent screen dimensions)
I didn't get this, could you explain a bit ? That might be interesting to implement :)
I think they mean take the x position and divide it by the width, that way you get a number between 0 and 1. This way, you can work with data from any screen widths. i.e. if you have code that says

Code: Select all

if screenWidth == 200 and playerX >= 200 then
elseif screenWidth == 400 and playerX >= 400 then
-- etc. etc.
end
You can just do something that says

Code: Select all

if playerRelativeX >= 1 then
end
Of course, you could also just do

Code: Select all

if playerX >= screenWidth then
end
but you get what I'm saying.

Re: push, a res-handling library

Posted: Mon Aug 17, 2015 2:13 pm
by Ulydev
So that'd just be a function that returns normalized coordinates ? Alright.

Re: push, a res-handling library

Posted: Tue Aug 18, 2015 7:40 pm
by Ulydev
Added mouse handling.

-push:toGame(x, y) returns relative-to-game coordinates. It's useful for in-game mouse position, for instance.
-push:toReal(x, y) returns relative-to-screen coordinates.

Re: push, a res-handling library

Posted: Mon Nov 02, 2015 5:53 pm
by Ulydev
Hello everyone!

This isn't dead. I just fixed some issues and added a new push:switchFullscreen() function to quickly switch between fullscreen and windowed mode. :awesome: