Writing a Library

Let's write a library for the Ichigo Template. Libraries are not protected by the ichi environment, but rather extend it via the table passed to them. They are automatically loaded before all plugins and main.lua. Libraries can also return Actors that will be added to the Actors table. Let's create a simple plugin that will allow us to draw an arbitrary quad.

circle-info

You can find libraries for Ichigo Template herearrow-up-right.

circle-exclamation

Navigate to the /lib folder and create a new file called drawing.lua. Inside, write the following:

local ichi = ... -- get environment
local quad

Next, let's write a function that will draw the quad. (Don't worry about quad being blank for now, we will create this later.)

ichi.drawQuad = function(x, y, sizex, sizey, rot, col)
  rot = rot or 0
  col = col or color("#FFFFFF")
  quad
    :visible(true)
    :xy(x, y)
    :SetSize(sizex, sizey)
    :rotationz(rot)
    :diffuse(col)
    :Draw()
    :visible(false)  
end

Now we can create and return our Quad Actor.

The entirety of the code should look like this:

Congrats! Your first library is now created. You can extend on this library by adding more elements to draw if you wish. We can use this library in a function specifically for drawing. Add this to main.lua:

Now you should see a small white Quad in the middle of the screen.

Last updated