Litgraphics - Doge2Dev/LitiumVM GitHub Wiki
Litgraphics
Litgraphics is the main function and is used to render objects on your game (Sprites & texts)
litgraphics.newSprite()
Used to draw sprite tables on screen
Usage
litgraphics.newSprite(table, spriteSize, xpos, ypos, tablePallete)
Parameter | Description |
---|---|
spriteSize | Change the sprite size |
xpos | X position to create sprite |
ypos | Y Position to create sprite |
tablePallete | Import pallete for specific sprite (if nil got the default pallete) |
Example :
function start()
heartPallete = {
{0,0,0,0},
{255,0,0},
{255,255,255}
}
Heart = {
{1,1,1,1,1,1,1,1,1},
{1,2,2,1,1,1,2,2,1},
{2,2,2,2,1,2,3,2,2},
{2,2,2,2,2,3,2,2,2},
{2,2,2,2,2,2,2,2,2},
{1,2,2,2,2,2,2,2,1},
{1,1,2,2,2,2,2,1,1},
{1,1,1,2,2,2,1,1,1},
{1,1,1,1,2,1,1,1,1},
}
end
function render()
-- Create the "Heart" sprite at position 16, 60 and use the color pallete "heartPallete"
litgraphics.newSprite(Heart, 16, 60, 60, heartPallete)
end
litgraphics.newText()
Used to display text on screen
Usage:
litgraphics.newText(textStr, textPosX, textPosY, fontSize, textColor, bgcolor)
Parameter | Description |
---|---|
textStr | The text you want display |
textPosX | The text position in X |
textPosY | The text position in Y |
FontSize | The size of the characters |
textColor | The color of the character of the |
bgColor | The background color of characters |
Example :
function render()
-- Create a text "Hello World" at position 90x and 90y with color 3 (WHITE) and background color 1 (TRANSPARENT')
litgraphics.newText("hello world", 90, 90, 8, 3, 1)
end
Litgraphics.rect()
Generate a rectangle
usage:
litgraphics.rect(xp, yp, wt, ht, color, fill)
parameter | description |
---|---|
xp | Position X |
yp | Position Y |
wt | Rectangle width |
ht | Rectangle Height |
color | Rectangle color |
fill | Select the mode to render / "fill" and "line" |
Example:
function render()
-- create a rectangle on position 90x 90y with witdh 32 height 32 with color 3 (WHITE) on "fill" mode
litgraphics.rect(90, 90, 32, 32, 3, "fill")
end
Ligraphics.clearScreen()
Clear the screen content
Usage:
litgraphics.clearScreen()
Example
function render()
litgraphics.clearScreen()
end
litgraphics.loadPallete()
Set a color pallete table.
Usage:
litgraphics.loadPallete(tablePallete)
Parameter | Description |
---|---|
tablePallete | The table with color data |
Example
function start()
-- here a table pallete for a heart sprite (color based on RGBA)
heartPallete = {
{0,0,0,0}, -- TRANSPARENT
{255,0,0}, -- RED
{255,255,255} -- WHITE
}
-- here our sprite, each numer correspond to a color position on color table
Heart = {
{1,1,1,1,1,1,1,1,1},
{1,2,2,1,1,1,2,2,1},
{2,2,2,2,1,2,3,2,2},
{2,2,2,2,2,3,2,2,2},
{2,2,2,2,2,2,2,2,2},
{1,2,2,2,2,2,2,2,1},
{1,1,2,2,2,2,2,1,1},
{1,1,1,2,2,2,1,1,1},
{1,1,1,1,2,1,1,1,1},
}
-- Loading our custom pallete (this will be the global pallete)
litgraphics.loadPallete(heartPallete)
end