This figure shows the architecture of an application created with Scrupp. The whole development happens on the right side using Lua.
On Windows the easiest way to use Scrupp is to let the installer associate script files (*.slua) and archives (*.sar) with Scrupp. That way, a double-click on one of these filetypes automatically runs the file with Scrupp.
Another possibility is to drop either a script file, an archive, or a directory on the executable scrupp.exe. The dropped file or directory becomes the first command line argument. See Using the Command Line for details.
On Linux you can either configure your file manager to open the script files (*.slua) and archives (*.sar) with Scrupp, or use the command line.
Drag and drop is supported as well (see Windows).
On Mac OS X the nescessary filetypes should be automatically associated with Scrupp. Thus, a double click on a script file (*.slua) or an archive (*.sar) should invoke Scrupp.
Drag and drop is supported as well (see Windows).
Scrupp supports zip archives. You can compress all the files belonging to your application to a single zip file. The extension of the file is not important, but the default for a Scrupp archive is *.sar. Scrupp can load the archive and executes the main script file called main.slua. It is important that this file is located in the root of the zip file.
wrong:
archive.sar \-- myApp (folder) \-- main.slua
right:
archive.sar \-- main.slua
The following list shows the possibilitis for running Scrupp from the command line.
$ scrupp [-- arg1 arg2 ... argN]
Scrupp tries to open the file main.slua
.
The working directory of the script will be the one containing
the executable. If this file is not found, Scrupp will try to
open the zip archive main.sar
which has to contain
the file main.slua
. If both files are not found,
an error will be thrown. Extra arguments
to the script have to be separated from the executable's name by
--
.
$ scrupp <Lua file> [arg1 arg2 ... argN]
Scrupp tries to execute the Lua file. The working directory will be the one containing the Lua file. It is possible to give extra arguments to the Lua file.
$ scrupp <zip archive> [arg1 arg2 ... argN]
The archive is prepended to the search path. The directory that
contains the archive becomes the working directory. After this
Scrupp tries to execute main.slua
which should be located
inside this archive. It is possible to give extra
arguments to the Lua file.
$ scrupp <directory> [arg1 arg2 ... argN]
The directory is prepended to the search path and set as the
working directory. After this Scrupp tries to execute
main.slua
which should be located inside this directory.
It is possible to give extra arguments to the
Lua file.
Before running a Lua file, Scrupp collects all command line
arguments in the global table arg
. The name of the
chosen Lua file, directory or archive becomes the element at index
0 in that table. Additional arguments are stored in index 1, 2 and
so on. The name of the executable goes to index -1. The script can
access these arguments by using arg[1], arg[2],
etc.
or the vararg expression '...'.
-- print the name of the script
print("name of the script:", arg[0])
-- print the number of arguments to the script
print("number of arguments:", select('#', ...) )
-- print all arguments
print("arguments:", ...)
-- this prints the first argument
print("Argument 1: ", arg[1] or "none")
-- exiting Scrupp
scrupp.exit()
Just save this example code in a file called
argtest.lua
and run
$ scrupp argtest.lua arg1 arg2
This can be done with every example from the manual. To get started have a look at the General Functions, save the example in a file and run this file with Scrupp.
Scrupp uses a so called virtual filesystem (VFS) which is implemented using the PhysicsFS library. The VFS consists of a list of paths to directories and archives - the search path.
Everytime a file is accessed using one of the Scrupp functions (e.g. scrupp.addImage()) every entry of the search path is checked for the existance of the specified file. If the file exists in multiple paths, the first one is chosen.
The standard io facilities of Lua (all functions in the global io table) do not support the virtual filesystem. These functions modify files in the working directory.
On startup, Scrupp constructs the search path and sets the working directory. In order to understand the way how that's done the following definitions are needed:
SHARE_DIR
${prefix}/share/scrupp
. The prefix is defined by the
configure script (default: /usr/local). During the installation,
all support files ("main.slua" and the directories "examples",
"fonts" and "scripts") are copied to this directory.The following figure shows Scrupp's behaviour on startup, i. e. how it sets the search path and working directory. Click it for a bigger version.
At the beginning, Scrupp runs a Lua file which is chosen depending on the command line arguments. Read "Getting Started" for details. This file can run other Lua files, load any media type, define functions and so on. It has to define a table with the name 'main' which contains the callbacks.
-- create a resizable window
scrupp.init("Callback Test", 600, 400, 32, false, true)
local image = scrupp.addImage("path_to_image_file")
main = {
render = function(dt)
image:render(mouse.getX(), mouse.getY())
end,
resized = function(width, height)
scrupp.init("Resized!", width, height, 32, false, true)
end,
mousepressed = function(x, y, button)
print(button .." button pressed at "..x..", "..y)
end,
mousereleased = function(x, y, button)
print(button .." button released at "..x..", "..y)
end,
keypressed = function(k)
if k == "ESCAPE" then
scrupp.exit()
end
print("key '" .. k .. "' pressed")
end,
keyreleased = function(k)
print("key '" .. k .. "' released")
end
}
The following set of functions modify the render state of Scrupp. That means, they change the way everything is rendered afterwards. This applies to the rendering of images, movies and drawings.
It's important to know, that the three functions to translate, scale and rotate the view influence each other depending on the order in which they are executed. The recommended order that usually does what you want is:
scrupp.init("Draw Test - Click to test!", 600, 400, 32, false)
-- prepare one table for big white pixels
local pixels = { antialiasing = false, size = 20, pixellist = true }
-- prepare one table for red connected lines
local lines = { color = {255,0,0}, antialiasing = true, connect = true }
main = {
render = function(dt)
scrupp.draw(lines)
scrupp.draw(pixels)
end,
mousepressed = function(x, y, button)
-- add the point where the mouse was pressed to the list of pixels
pixels[#pixels+1] = x
pixels[#pixels+1] = y
-- add the point to the list of lines, too
lines[#lines+1] = x
lines[#lines+1] = y
end
}
table = { x, -- x-coordinate of the image position -- mandatory y, -- y-coordinate of the image position -- mandatory centerX = [x-coordinate of the center for positioning, scaling and rotation], -- optional centerY = [y-coordinate of the center for positioning, scaling and rotation], -- optional scaleX = [scale factor for the x-axis], -- optional scaleY = [scale factor for the y-axis], -- optional rotate = [angle in degrees to rotate the image], -- optional rect = { x, y, width, height }, -- optional color = { red, green, blue, alpha } -- optional }The first two elements of the array part of the table have to be the x- and y-coordinate of the point that the image should be rendered at. The table may have an optional rect entry. This has to be a table describing the rectangle the image should be clipped to. It contains the x- and y-coordinate of the top left corner and the width and height of the rectangle inside the image. The entries centerX and centerY are optional and default to zero, the top left corner of the image. scaleX and scaleY are optional as well and default to one. rotate has a default value of zero dregrees and is optional, too. The optional color entry is a table defining some kind of color filter. If you have a grayscale image, it will be colorized with this color. As always the table looks like this: {red, green, blue, [alpha]} with each value between 0 and 255. The default is opaque white, so the color of the image is not changed.
scrupp.init("Image Test", 600, 400, 32, false)
-- load an image file
local image = scrupp.addImage("path_to_image_file")
-- get the dimension of the image
local width = image:getWidth()
local height = image:getHeight()
-- this has the same result:
local width, height = image:getSize()
if width > scrupp.getWindowWidth() or height > scrupp.getWindowHeight() then
print("Please choose an image with smaller dimensions.")
scrupp.exit()
end
-- calculate the x- and y-coordinate of the image
local x = (scrupp.getWindowWidth()-width)/2
local y = (scrupp.getWindowHeight()-height)/2
main = {
render = function(dt)
-- get the position of the mouse pointer
mx, my = mouse:getPos()
-- set the image alpha depending on the x-coordinate of the
-- mouse pointer
image:setAlpha(mx/scrupp.getWindowWidth()*200+50)
-- if you click with the left mouse button,
-- only a part of the image is rendered
if mouse.isDown("left") then
image:render{
mx, my,
rect = { mx-x, my-y, width/2, height/2 }
}
-- otherwise the whole image is rendered
else
image:render(x,y)
end
end
}
Scrupp 0.4 contains version 1.2 of the Cairo binding lua-oocairo written by Geoff Richards.
By using this Cairo binding it is possible to generate images. Due to the runtime generation these images can be completely resolution independant.
Another possibility is the creation of PNG, PDF, PS and SVG files.
The original website of lua-oocairo (http://www.daizucms.org/lua/library/oocairo/) is no longer available on the web. That's why I have uploaded a copy on this website. It contains the documentation of lua-oocairo.
The doc directory of the Scrupp distribution contains the lua-oocairo documentation as well.
In order to ease the usage of Cairo from Scrupp, the binding was modified and new functions were added to Scrupp.
-- load the Cairo library
local Cairo = require "oocairo"
-- create an image surface with a size of 200x200 pixel
local surface = Cairo.image_surface_create("rgb24", 200, 200)
-- create a Cairo context used for drawing
local cr = Cairo.context_create(surface)
-- create some arbitrary shapes
cr:set_source_rgb(1, 1, 1)
cr:paint()
cr:move_to(0, 0)
cr:line_to(190, 100)
cr:line_to(100, 185)
cr:line_to(200, 200)
cr:line_to(30, 130)
cr:close_path()
cr:set_source_rgb(0.8, 0.4, 1)
cr:fill()
cr:move_to(180, 30)
cr:line_to(100, 20)
cr:line_to(80, 120)
cr:set_source_rgb(0.5, 0.7, 0.3)
cr:fill_preserve()
cr:set_source_rgb(0, 0, 0)
cr:set_line_width(3)
cr:stroke()
-- use scrupp to display the surface
scrupp.init("Cairo: simple-example", 200, 200, 32, false)
-- convert the Cairo surface to a Scrupp image
local image = scrupp.addImageFromCairo(surface)
main = {
render = function(dt)
image:render(0,0)
end,
keypressed = function(key)
if key == "ESCAPE" then
scrupp.exit()
end
end
}
Have a look at the font plugin. This makes the usage of truetype fonts easier.
Scrupp supports UTF-8. If you want to use this feature, remember to edit your scripts using the UTF-8 mode of your editor. Save them with UTF-8 encoding (without BOM).
table = { text, color = {red, green, blue, [alpha]} -- optional }The first element of the array part of the table has to be the text. The table may have an optional color entry. This has to be a table containing three numbers between 0 and 255, one for each color component (red, green, blue). An optional fourth entry is the transparency (0-255).
scrupp.init("Font Test", 600, 400, 32, false)
-- load a font
local font = scrupp.addFont("fonts/Vera.ttf", 20)
-- get the recommended line height in pixel
local lineSkip = font:getLineSkip()
-- get the text size of a sample text
local w, h = font:getTextSize("Hello World")
-- define a color (opaque blue)
local cBlue = {0, 0, 255, 255}
-- the transparency defaults to 255 (opaque), so this is the same:
local cBlue = {0, 0, 255}
-- generate an image containing some text using the default color
local image_1 = font:generateImage("Hello World")
-- generate an image using the defined color cBlue
-- -- because font:generateImage() gets only one parameter and this is a table
-- -- we can omit the parenthesises and just use the curly brackets of the table
-- -- constructor
local image_2 = font:generateImage{"Hello World", color = cBlue}
-- this has the same result:
local image_2 = font:generateImage{"Hello World", color = {0, 0, 255}}
main = {
render = function(dt)
-- render the already loaded images:
image_1:render(100,50)
image_2:render(100 + w, 50 + lineSkip)
end
}
The sound support is implemented using SDL_mixer.
Note: If you load a sound and play it multiple times in parallel all sound manipulating methods will affect every instance of this sound!
scrupp.init("Sound Test", 600, 400, 32, false)
-- load a sound file
local sound = scrupp.addSound("path_to_sound_file")
main = {
-- empty render function
render = function(dt)
end,
-- play the sound every time a mouse button is pressed
mousepressed = function(x, y, button)
sound:play()
end
}
The music support is implemented using SDL_mixer.
Scrupp supports only one music file playing at a time. Because of that there is only one method for a music object: play. All the other music manipulating functions are independant from a special music object. They change whatever music file is playing at the moment.
$ id3convert -s -2 <mp3 file>
scrupp.init("Music Test", 600, 400, 32, false)
-- load some music
local music = scrupp.addMusic("path_to_music_file")
-- start music
music:play()
main = {
-- empty render function
render = function(dt)
end
}
Movie support is implemented using SMPEG.
Scrupp only supports MPEG-1 videos! Furthermore automatic aspect ratio correction is not implemented. For example, a video file has a resolution of 352x240 (= 1.47:1) but the aspect ratio is defined by the header as 1.34:1. Therefore the video has to be resized in order to correct the aspect ratio. A resolution of 352x262 satisfies the ratio. The scale factor in vertical direction calculates to 262/240 = 1.09.
The recommended way to convert video files to the MPEG-1 format is using MEncoder, a command line program which is a part of MPlayer. It is available for all major platforms.
I got good results with the following command:
mencoder -oac lavc -ovc lavc \ -of mpeg -mpegopts format=mpeg1 \ -vf harddup -srate 44100 -af lavcresample=44100 \ -lavcopts vcodec=mpeg1video:acodec=mp2 -ofps 25 -mc 0 -noskip \ -o output.mpeg movie.file
table = { hasAudio = boolean, hasVideo = boolean, currentFrame = integer, currentFPS = number, -- frames per second audioString = string, -- e.g. "MPEG-1 Layer 2 128kbit/s 44100Hz stereo" currentAudioFrame = integer, currentOffset = integer, totalSize = integer, -- filesize in bytes currentTime = number, -- in seconds totalTime = number -- in seconds }
table = { x, -- x-coordinate of the movie frame position -- mandatory y, -- y-coordinate of the movie frame position -- mandatory centerX = [x-coordinate of the center for positioning, scaling and rotation], -- optional centerY = [y-coordinate of the center for positioning, scaling and rotation], -- optional scaleX = [scale factor for the x-axis], -- optional scaleY = [scale factor for the y-axis], -- optional rotate = [angle in degrees to rotate the movie frame], -- optional rect = { x, y, width, height }, -- optional color = { red, green, blue, alpha } -- optional }The first two elements of the array part of the table have to be the x- and y-coordinate of the point that the movie frame should be rendered at. The table may have an optional rect entry. This has to be a table describing the rectangle the movie frame should be clipped to. It contains the x- and y-coordinate of the upper left corner and the width and height of the rectangle inside the movie frame. The entries centerX and centerY are optional and default to zero, the left-upper corner of the movie frame. scaleX and scaleY are optional as well and default to one. rotate has a default value of zero dregrees and is optional, too. The optional color entry is a table defining some kind of color filter. If you have a grayscale movie, it will be colorized with this color. As always the table looks like this: {red, green, blue, [alpha]} with each value between 0 and 255. The default is opaque white, so the color of the movie frame is not changed.
-- create a dummy window, because you have to call
-- scrupp.init() before you can load movies
scrupp.init("Movie Test", 10, 10, 32, false)
-- load a mpeg file
local movie = scrupp.addMovie("path_to_mpeg_file")
-- get the width and height of the movie
local width, height = movie:getSize()
-- resize the Scrupp window to the movie size
scrupp.init("Movie Test", width, height, 32, false)
-- play the movie in a loop
movie:play(true)
main = {
render = function(dt)
movie:render(0,0)
end,
keypressed = function(k)
if k == "ESCAPE" then scrupp.exit() end
end,
}
scrupp.init("Mouse Test", 600, 400, 32, false)
require "font"
local font = Font("fonts/Vera.ttf", 20)
local text = ""
local cursor = scrupp.addImage("path_to_cursor_image")
main = {
render = function(dt)
font:print(10,10, text)
if scrupp.mouseButtonIsDown("left") then
cursor:render(scrupp.getMouseX(), scrupp.getMouseY())
--or: cursor:render(scrupp.getMousePos())
end
end,
mousepressed = function(x, y, button)
text = button .." button pressed at "..x..", "..y
end,
mousereleased = function(x, y, button)
text = button .." button released at "..x..", "..y
end
}
The first table shows virtual key strings. These keys do not exist. You should not try to use them with the callbacks. Instead of e.g. "SHIFT", test for "LSHIFT" or "RSHIFT"
They should be used with scrupp.keyIsDown() to test for some special keys which happen to be twice on a standard keyboard. scrupp.keyIsDown("SHIFT") will return true if either of the two shift keys is pressed.
"SHIFT" | either of the shift keys |
"CTRL" | either of the ctrl keys |
"ALT" | either of the alt keys |
"META" | either of the meta keys |
"SUPER" | either of the windows keys |
The following table shows all key strings usable with Scrupp.
"UNKNOWN" | unknown key |
"BACKSPACE" | backspace |
"TAB" | tab |
"CLEAR" | clear |
"RETURN" | return |
"PAUSE" | pause |
"ESCAPE" | escape |
"SPACE" | space |
"!" | exclaim |
""" | quotedbl |
"#" | hash |
"$" | dollar |
"&" | ampersand |
"'" | quote |
"(" | left parenthesis |
")" | right parenthesis |
"*" | asterisk |
"+" | plus sign |
"," | comma |
"-" | minus sign |
"." | period |
"/" | forward slash |
"0" | 0 |
"1" | 1 |
"2" | 2 |
"3" | 3 |
"4" | 4 |
"5" | 5 |
"6" | 6 |
"7" | 7 |
"8" | 8 |
"9" | 9 |
":" | colon |
";" | semicolon |
"<" | less-than sign |
"=" | equals sign |
">" | greater-than sign |
"?" | question mark |
"@" | at |
"[" | left bracket |
"\" | backslash |
"]" | right bracket |
"^" | caret |
"_" | underscore |
"`" | grave |
"a" | a |
"b" | b |
"c" | c |
"d" | d |
"e" | e |
"f" | f |
"g" | g |
"h" | h |
"i" | i |
"j" | j |
"k" | k |
"l" | l |
"m" | m |
"n" | n |
"o" | o |
"p" | p |
"q" | q |
"r" | r |
"s" | s |
"t" | t |
"u" | u |
"v" | v |
"w" | w |
"x" | x |
"y" | y |
"z" | z |
"DELETE" | delete |
"KP0" | keypad 0 |
"KP1" | keypad 1 |
"KP2" | keypad 2 |
"KP3" | keypad 3 |
"KP4" | keypad 4 |
"KP5" | keypad 5 |
"KP6" | keypad 6 |
"KP7" | keypad 7 |
"KP8" | keypad 8 |
"KP9" | keypad 9 |
"KP_PERIOD" | keypad period |
"KP_DIVIDE" | keypad divide |
"KP_MULTIPLY" | keypad multiply |
"KP_MINUS" | keypad minus |
"KP_PLUS" | keypad plus |
"KP_ENTER" | keypad enter |
"KP_EQUALS" | keypad equals |
"UP" | up arrow |
"DOWN" | down arrow |
"RIGHT" | right arrow |
"LEFT" | left arrow |
"INSERT" | insert |
"HOME" | home |
"END" | end |
"PAGEUP" | page up |
"PAGEDOWN" | page down |
"F1" | F1 |
"F2" | F2 |
"F3" | F3 |
"F4" | F4 |
"F5" | F5 |
"F6" | F6 |
"F7" | F7 |
"F8" | F8 |
"F9" | F9 |
"F10" | F10 |
"F11" | F11 |
"F12" | F12 |
"F13" | F13 |
"F14" | F14 |
"F15" | F15 |
"NUMLOCK" | numlock |
"CAPSLOCK" | capslock |
"SCROLLOCK" | scrollock |
"RSHIFT" | right shift |
"LSHIFT" | left shift |
"RCTRL" | right ctrl |
"LCTRL" | left ctrl |
"RALT" | right alt |
"LALT" | left alt |
"RMETA" | right meta |
"LMETA" | left meta |
"LSUPER" | left windows key |
"RSUPER" | right windows key |
"MODE" | mode shift |
"COMPOSE" | compose |
"HELP" | help |
"PRINT" | print-screen |
"SYSREQ" | SysRq |
"BREAK" | break |
"MENU" | menu |
"POWER" | power |
"EURO" | euro |
"UNDO" | undo |
The source of this table is the SDL man page for SDLKey.
Additionally, there exist strings for keys on international keyboards. They are named from "WORLD_0" to "WORLD_95".
scrupp.init("Keyboard Test", 600, 400, 32, false)
require "font"
local font = Font("fonts/Vera.ttf", 20)
local text = "Press any key."
main = {
render = function(dt)
font:print(10, 10, text)
end,
keypressed = function(key)
text = key .. " pressed."
-- the escape key exits the demo
if key == "ESCAPE" then
scrupp.exit()
end
end,
keyreleased = function(key)
text = key .. " released."
end
}
Scrupp 0.4 contains version 2.0.2 of the Lua network library LuaSocket written by Diego Nehab.
The website of LuaSocket contains an introduction and a reference.
The doc directory of the Scrupp distribution contains a local snapshot of the LuaSocket documentation.
Everything described in this documentation works exactly the same way in Scrupp.
-- size of the window
local width, height = 600, 400
scrupp.init("LuaSocket Test", width, height, 32, false)
-- loads the HTTP module and any libraries it requires
local http = require("socket.http")
-- download a screenshot from the scrupp website
local img = http.request("http://scrupp.sourceforge.net/screenshots/linux_default_thumb.png")
-- convert the string to a scrupp image
img = scrupp.addImageFromString(img)
-- get the size of the image
local w, h = img:getSize()
-- calculate the coordinates of the image (for center position)
local x, y = (width-w)/2, (height-h)/2
main = {
render = function(dt)
-- render the screenshot at the center of the window
img:render(x,y)
end,
keypressed = function(key)
if key == "ESCAPE" then
scrupp.exit()
end
end
}
This is a simple class implementation. It was taken from the lua-users wiki. The original author is unknown.
The returned objects can be used to create new instances. Any changes to the returned object will influence all instances of this class. An example usage of this feature is the implementation of methods after the creation of the class.
If a new instance of a class is created, the constructor will be called with the new instance as first parameter followed by any additional parameters. The constructor can be used to set any values of the new instance to either default values or values which depend on the additional parameters.
In order to create a new instance of a class just call the object returned by the class function with any optional arguments to the constructor.
Every instance of a new class implements the following methods.
scrupp.init("Class Test", 600, 400, 32, false)
-- load required plugin
require "font"
-- load a font
local font = Font("fonts/Vera.ttf", 20)
-- define a class for animals
local Animal = class(function(a, name)
a.name = name
end)
-- define a method that returns the name of the animal
function Animal:getName()
return self.name
end
-- define a class for dogs
local Dog = class(Animal, function(a, name, lord)
a.name = name
a.lord = lord
end)
-- define a method that returns the name of the lord of the dog
-- remark: the method getName() is taken from the base class
function Dog:getNameOfLord()
return self.lord
end
-- create an instance of the class Dog
local Hasso = Dog("Hasso", "Mr. Smith")
main = {
render = function(dt)
font:print(10,10, "Name: ", Hasso:getName())
font:print(10,40, "Lord: ", Hasso:getNameOfLord())
-- tostring() is nescessary in order to print a boolean value
font:print(10,70, "Hasso is an animal: ", tostring(Hasso:is_a(Animal)))
font:print(10,100, "Hasso is a dog: ", tostring(Hasso:is_a(Dog)))
end
}
This class provides an easy to use interface for animations.
You can download an example image that contains the frames of an animation which can be used with the example below: animation.png.
scrupp.init("Animation Test", 600, 400, 32, false)
-- load required plugins
require "animation"
-- create a new animation
local animation = Animation()
-- loads the frames from animation.png which contains 3x2 = 6
-- single frames, each with a size of 48x48 pixels, with no
-- separating pixels in between
-- each frame is shown for one second (1000 milliseconds)
animation:addFrames("animation.png", 3, 2, 48, 48, 0, 1000)
main = {
render = function(dt)
animation:render(10,10, dt)
end
}
This plugin provides a table containing some often used colors.
The execution of require "color" creates a table, returns it and stores it in the global variable named color. This table contains the tables of the provided colors. They can be accessed by the name of the color. Each color table has the format {red, green, blue}, with each component being an integer from 0 to 255. These colors can be used everytime scrupp expects a color.
scrupp.init("Color Test", 600, 357, 32, false)
-- load the color plugin and store it in a local variable
-- for faster access
local color = require "color"
-- alternative:
-- require "color"
-- this example uses the font plugin
require "font"
local font = Font("fonts/Vera.ttf", 20)
-- generate a rectangle
local rect = {
100, 0, -- placeholder for the coordinates
0, 0,
495, 0,
495, 18,
0, 18,
relative = true,
fill = true
}
-- y-position of the displayed color
local y
main = {
render = function(dt)
y = 5
-- cycle through all available colors
for name, color in pairs(color) do
-- print the name of the color
font:print(10, y, name)
-- change the color of the rectangle
rect.color = color
-- change the y-coordinate of the rectangle
rect[2] = y
-- draw the colored rectangle
scrupp.draw(rect)
y = y + 22
end
end
}
This class provides a high level interface to TTF fonts. If you want to print some text to the screen by only using the functions provided by the core of Scrupp, you will have to create a new image for every text. This is very inefficient if the text changes in every frame. This class creates an image for every single letter and prints text to the screen by placing them in the right order.
This plugin supports UTF-8. If you want to use this feature, remember to edit your scripts using the UTF-8 mode of your editor. Save them with UTF-8 encoding (without BOM).
In typography, kerning is the process of adjusting letter spacing in a proportional font. In a well-kerned font, the two-dimensional blank spaces between each pair of letters all have similar area (source: Wikipedia). This plugin supports autokerning. You don't have to do anything, your texts will just look right.
scrupp.init("Font Test", 600, 400, 32, false)
-- load required plugin
require "font"
local font = Font("fonts/Vera.ttf", 20)
main = {
render = function(dt)
font:print(10,10, "Hello world!")
font:print(10,40, "Hello ", "world!")
font:print(10,70, "Strings with embedded newlines\nare supported as well.")
end
}
This class provides an implementation of timers.
scrupp.init("Timer Test", 600, 400, 32, false)
-- load required plugins
require "font"
require "timer"
local font = Font("fonts/Vera.ttf", 20)
-- this variable is used to distinguish between tick and tack :)
local tick = true
-- create a new timer with a duration of 1 second
-- (= 1000 milliseconds)
-- the callback negates the tick variable
local timer = Timer(1000, function(timer)
tick = not tick
end)
-- start the timer
timer:start()
main = {
render = function(dt)
-- update the timer
timer:update()
-- print Tick or Tack depending on the state of the
-- tick variable
if tick then
font:print(10,10, "Tick!")
else
font:print(10,10, "Tack!")
end
end
}