Difference between revisions of "TLfres"

m (Updated license note)
m (Corrected a parameter's description)
Line 30: Line 30:
 
== Functions ==
 
== Functions ==
 
====TLfres.setScreen====
 
====TLfres.setScreen====
<source lang="lua">TLfres.setScreen(mode, wextent, hextent, centered, stretch)</source>
+
<source lang="lua">TLfres.setScreen(mode, extent, centered, stretch)</source>
 
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.
 
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.
 
{{param|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 <code>{w=800, h=600, full=false, vsync=false, aa=0}.</code>
 
{{param|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 <code>{w=800, h=600, full=false, vsync=false, aa=0}.</code>
{{param|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..
+
{{param|number|extent (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 normalized 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..
{{param|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.
+
 
{{param|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.
 
{{param|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.
 
{{param|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().
 
{{param|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().

Revision as of 17:48, 7 October 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!

It's under the ZLIB license.

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, extent, 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 extent (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 normalized 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..
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.