tapir / CScreen

A simple way to make resolution-independent Love2D games

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CScreen

A simple way to make resolution-independent Love2D games, by CodeNMore. This allows your game to be resized to any resolution by the user and still keep the aspect ratio and look pretty!

This version (1.3) has been tested (and works!) with LOVE 0.10.1

Basic Usage

CScreen is very simple to use, and can be implemented in nearly any type of game. Simply place the cscreen.lua OR cscreen.min.lua file into your game directory, and follow the example below:

local CScreen = require "cscreen"

function love.load()
	CScreen.init(800, 600, true)
end

function love.draw(dt)
	CScreen.apply()
	-- Draw all of your objects here!
	CScreen.cease()
end

function love.resize(width, height)
	CScreen.update(width, height)
end

Basic Documentation

Function Parameters Description
init(tw, th, center) tw (800) the target screen width
th (600) the target screen height
center (true) whether or not to letterbox
Use tw and th to set the target width and height of the game screen. This defaults to 800 and 600, or a 4:3 screen ratio. Set center to true to center, or letterbox, the game screen (generally this should be true). Usually this is called in love.load().
update(w, h) w (int) the new screen width
h (int) the new screen height
This allows CScreen to continue to properly resize the graphics. Usually this is called in love.resize(w, h) passing along the new screen width and height to the update function.
apply() none Will apply any calculations to properly draw the screen. Usually this is called at the beginning of love.draw(dt). This function utilizes love.graphics.translate(..) for centering and love.graphics.scale(..) for fitting.
cease() none Actually draws the letterbox borders using love.graphics.rectangle(..) using the set color (see setColor()), then restores the previously set color. **This is called at the end of love.draw(dt), as drawing after this line will result in an incorrect ratio!
setColor(r, g, b, a) r (0) red
g (0) green
b (0) blue
a (255) alpha
Sets the color to use for the screen letterbox borders (default is black).

About

A simple way to make resolution-independent Love2D games

License:Other


Languages

Language:Lua 100.0%