Home

Awesome

terebi

Build Status Codecov Love Versions Public Domain

A simple library to handle pixel-perfect scaling of window content in Love2D. Its features are:

Example

local Terebi = require 'terebi'
local screen

function love.load(arg)
  -- Set nearest-neighbour scaling. (Optional)
  Terebi.initializeLoveDefaults()

  -- Parameters: game width, game height, starting scale factor
  screen = Terebi.newScreen(320, 240, 2)
    -- This color will used for fullscreen letterboxing when content doesn't fit exactly. (Optional)
    :setBackgroundColor(0.25, 0.25, 0.25)
end

function love.keypressed(key)
  local isAltDown = love.keyboard.isDown('ralt') or love.keyboard.isDown('lalt')
  if     key == '+' then
    screen:increaseScale()
  elseif key == '-' then
    screen:decreaseScale()
  elseif key == 'f11' or (isAltDown and key == 'return') then
    screen:toggleFullscreen()
  end
end

local function drawFn()
  -- <Your drawing logic goes here.>
end

function love.draw()
  screen:draw(drawFn) -- Additional arguments will be passed to drawFn.
end

function love.resize(w, h)
  screen:handleResize()
end

Additional Functionality

-- Sets the scale factor.
screen:setScale(3)

-- Gets the current scale factor.
screen:getScale()

-- Sets scale to the largest factor which can fit on the current monitor.
screen:setMaxScale()

-- Gets the position of the mouse cursor in virtual screen (game) coordinates.
local mouseX, mouseY = screen:getMousePosition()

-- Converts window coordinates to virtual screen (game) coordinates.
local gameX, gameY = screen:windowToScreen(windowX, windowY)

-- Converts virtual screen (game) coordinates to window coordinates.
local windowX, windowY = screen:screenToWindow(gameX, gameY)

Installation

Copy terebi.lua into your game directory and require 'terebi'.

Todo