Welcome to the library documentation! Here you can find out what you can do with this library! Enough padding, here's the table of contents:
smilebasic.lua
?Want to start making things, but don't want to read through the entire documentation? Here's a small starter program I wrote for you. Replace the game.lua
file in the base directory with this, and you'll get some text that prints every frame!
-- This only happens once
function setup()
-- Make a table to hold all the elements we want to update and draw each frame
sb = {}
-- Make a text screen
t = Text.new(50, 30) -- Make a 50x30 text screen
table.insert(sb, t) -- Add its reference to the "sb" table.
t:fakeBoot() -- Add a fake boot screen.
t:color(0, 15) -- Make the text transparent on a background of white.
-- Print some test text to the text screen
-- Note that this does not have a second argument, so it will put a line break at the end.
t:print("This is an example script showcasing the Love2D SmileBASIC Library, a library for constructing Love2D games with a SmileBASIC aesthetic.")
-- Make a bunch of sprites
for i = 0, 63 do
s = Sprites.new(i) -- Make a sprite
table.insert(sb, s) -- Add its reference to the "sb" table.
s:offset(8 + (i % 16) * 16, 72 + math.floor(i / 16) * 16) -- Show it in a grid
s:home(8, 8) -- Set sprite's home to center of sprite
end
-- Make a background
b = Backgrounds.new(25, 15) -- It's 25x15 tiles
table.insert(sb, b) -- Add its reference to the "sb" table.
b:print("FAKE BACKGROUND TEXT!", 0, 12) -- Special command for writing characters
end
-- Every frame, do this
function update()
-- We didn't lose the text reference, so print some text every few frames
if window.frames % 8 == 0 then -- My "built-in" frames variable
t:print("Hello, world! ", false) -- We don't want a line break, so put false at the end.
end
-- Handle callbacks and animations, neither of which you're currently using. Still useful.
for i = 1, #sb do
sb[i]:update()
end
end
-- When it's time to draw the frame, do this
function draw()
-- Yes, you have to manually clear the screen.
love.graphics.clear(0, 0, 0)
-- Z-sort everything you added
ZSort.clear()
for i = 1, #sb do
ZSort.add(sb[i])
end
ZSort.flush()
end
smilebasic.lua
?smilebasic.lua
is a sort of abstract class written by a person who doesn't understand abstract classes, that is only used internally. Please don't use it.
If you're wondering what it does, it contains one function: SmileBASIC.add()
. This function will add some functions and variables to a table given to it. It adds properties like color, offset, scale, and rotation. It also adds some helper functions, such as sb:offset()
, sb:scale()
, and sb:runCallbacks()
. These functions will be explained in the General functions section. Oh, that seems to be the next one!
o:offset(x?, y?, z?) -> x, y, z
o:home(x?, y?) -> x, y
o:rotation(r?) -> r
o:color(r?, g?, b?, a?) -> r, g, b, a
o:scale(x?, y?) -> x, y
o:addCallback(callback)
o:update()
.
o:removeCallback(callback)
o:variable(index, value?) -> value
o:clear()