Difference between revisions of "TLfres"

m (Forgot to add the link to a screenshot)
m (TLfres.letterbox: transform -> letterbox)
Line 41: Line 41:
  
 
====TLfres.letterbox====
 
====TLfres.letterbox====
<source lang="lua">TLfres.transform(w, h, c)</source>
+
<source lang="lua">TLfres.letterbox(w, h, c)</source>
 
If not stretching the graphics (see TLfres.setScreen()), call this at the end of [[love.draw]](), after drawing everything. This draws letterboxes to trim any graphics which should be out of the screen. It defaults to the aspect ratio 4:3 with black letterboxes.
 
If not stretching the graphics (see TLfres.setScreen()), call this at the end of [[love.draw]](), after drawing everything. This draws letterboxes to trim any graphics which should be out of the screen. It defaults to the aspect ratio 4:3 with black letterboxes.
 
{{param|number|w (4)|The width of the aspect ratio the game is meant to have.}}
 
{{param|number|w (4)|The width of the aspect ratio the game is meant to have.}}

Revision as of 16:34, 28 April 2011

About

TLfres aims to make it extremely easy to make any game run at any screen resolution. Using it doesn't even require you to rewrite your graphics code!

Download

Direct from Dropbox

Contact

  • Taehl - SelfMadeSpirit@gmail.com

Setup

Everything in the module is contained in the TLfres namespace, so don't worry about it messing with your global variables. Assuming your game was built to use the Love-default resolution of 800x600:

  1. Put TLfres.lua in your game's folder
  2. At the top of main.lua, add the line require"TLfres"
  3. At the beginning of love.draw(), add the line TLfres.transform()
  4. At the bottom of love.draw() add the line TLfres.letterbox(4,3)

FAQ

Q) Why should I use this instead of love.graphics.scale?
A) Because even stretching the screen to a given res requires tricky math, which TLfres can do for you. Furthermore, most people hate stretched graphics - that's why you should use TLfres's letterboxing option. Instead of stretching the screen, it resizes it in the correct ratio and draws black boxes at the top and bottom if needed.
Q) What resolutions / aspect ratios does it support?
A) Theoretically, any. However, letterboxes act weird if you use a screen taller than it is wide.
Q) I made my game to use a non-default resolution. Will I have to change everything to make TLfres work with it?
A) Nope! Just call TLfres.setScreen() with the resolution you built your game for (see below).

Functions

TLfres.setScreen

TLfres.setScreen(mode, wextent, hextent, centered, stretch)

Call this INSTEAD of love.graphics.setMode! This will both configure TLfres and change resolution. If your game was originally made to use the default Love screen of 800x600, you don't need to use any parameters.

table mode
This table specifies screen geometry. It may contain the following data: w (the width of the screen, in pixels), h (the height of the screen, in pixels), full (whether to use fullscreen or not), vsync (whether to use vsync or not), aa (how many antialiasing samples to use). Defaults to {w=800, h=600, full=false, vsync=false, aa=0}.
number wextent (800)
The width of the screen that the game was originally programmed to use. Alternately, if you're making a new game using TLfres, this number can be whatever you want to represent the width of the screen in your code. For instance, I like using the number 1, so all coordinates are decimals (this makes the most sense to me). You could use 100 if you prefer to think in percentages (drawing something at x=50 would be the middle of the screen in this case), etc..
number hextent (600)
The height of the screen that the game was originally programmed to use. wextent and hextent default to 800 and 600, so if your game was made for Love's default screen, you don't need to pass these parameters.
boolean centered (false)
If false, the coordinate 0,0 is located at the top-left of the screen, as in default Love. If true, 0,0 is the center of the screen. This should be false if you're adding TLfres to an existing game, but may be set to taste when programming a new game.
boolean stretch (false)
If true, graphics will be stretched to fill the entire screen at any res. If the aspect ratio the game was programmed to use is different from the aspect ratio of the screen, stretching will occur. Some people prefer this to letterboxing, so it's a matter of personal taste. If you don't stretch, make sure to call TLfres.letterbox() at the end of love.draw().

TLfres.transform

TLfres.transform()

Call this at the very beginning of love.draw(), before drawing anything. This scales and translates the screen coordinates as needed by the current screen resolution. If you want to draw something at absolute screen coordinates, you may want to use love.graphics.push() before calling TLfres.transform().

TLfres.letterbox

TLfres.letterbox(w, h, c)

If not stretching the graphics (see TLfres.setScreen()), call this at the end of love.draw(), after drawing everything. This draws letterboxes to trim any graphics which should be out of the screen. It defaults to the aspect ratio 4:3 with black letterboxes.

number w (4)
The width of the aspect ratio the game is meant to have.
number h (3)
The height of the aspect ratio the game is meant to have.
table c {0,0,0, 255}
The color of the letterboxes, given in RGBA (just like love.graphics.setColor). Defaults to black.