WARNING : Don't use this current version for serious project ! This is currently not optimized !
So, what is it ? This library allow you to create canvas of text. Yes, of text. Each canvas are subdivided in "slot", which contain a character, an attribute, a foreground color and a background color. This library allow you to have console-like graphics for your game, but it allow you to have fine graphics too (images, lines, etc) !
All the source code are documented.
There is a little example :
Code: Select all
-- Include the library.
AC = require "AsciiCanvas"
function love.load ()
love.graphics.setBackgroundColor (128, 128, 128)
-- Create a new canvas.
canvas = AC.AsciiCanvas:new (80, 24)
-- Render it to a Love2D canvas.
canvas:renderToCanvas ()
-- Fill an area of the canvas.
canvas:fill (5, 5, 25, 10, " ", {255, 0, 0}, {0, 200, 0})
-- Add a character.
canvas:put (5, 5, "+")
canvas:put (30, 15, "+")
-- Add a string.
canvas:putString (11, 11, "Huehuehue ! :D")
-- Render to the canvas.
canvas:render ()
end
function love.draw ()
-- Get the size in pixel of the canvas.
local cw, ch = canvas:getSizeInPixel ()
-- Center the canvas.
local w, h = love.window.getDimensions ()
local x, y = w/2 - cw/2, h/2 - ch/2
-- Draw the canvas to the screen.
love.graphics.draw (canvas:target(), x, y)
end
Links : Some notes :
- It's preferred to use the canvas render mode, because it's more optimized than the direct render mode. For explanation : In this mode, the renderer render all the canvas only when it's needed (when it's created or cleared), and after this first draw on the Love2D canvas, the canvas will only render change : if you change one slot, and then call the render function, the renderer will only render the modified slot, and not all the canvas again.
- In canvas render mode, you shouldn't draw on the Love2D canvas. You can get some funny results
- You can use it freely, even for commercial game. But you need to credit my name and my library ( "This game use AsciiCanvas made by Linkpy" Place this somewhere. I know you can do it ! ).
- Whole rewrite : using C structures for reduce memory usage.
- Optimizing drawing : using SpriteBatch for minimizing love.graphics.draw calls.
Code: Select all
-- 15/07/2015 :
-- Added the "AsciiImage" class. Allowing user to save and to load AsciiImage.