push - a resolution-handling library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

push - a resolution-handling library

Post 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
Last edited by Ulydev on Tue Jun 28, 2016 7:21 pm, edited 7 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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")?
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

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

Post 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).
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

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

Post 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 :)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: push, a res-handling library

Post by bartbes »

Does it also deal with the mouse position?
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: push, a res-handling library

Post by Ulydev »

Oh, it actually doesn't. I might add it indeed.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: push, a res-handling library

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: push, a res-handling library

Post by Ulydev »

So that'd just be a function that returns normalized coordinates ? Alright.
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: push, a res-handling library

Post 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.
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: push, a res-handling library

Post 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:
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests