Skip to content

Using all the libraries

Pablo Mayobre edited this page Mar 25, 2015 · 5 revisions

#Using the whole set of Libraries

If after reading through all the features this library provides you have come here then that is Awesome!

Using this library as a set instead of as separated libraries is way easier. You just need to require material-love inside love.load (it needs access to the LÖVE modules)

local m

love.load = function ()
    m = require "material-love"
end

Now you have access to all the modules inside material-love

Modules

Shadows

To use shadows you can just call m.shadow in your love.draw function:

love.draw = function ()
    m.shadow.draw(x,y,w,h,center,pad,depth)
end

The PatchObject is stored in m.shadow.patch for you to access it methods and properties.

For more info on the parameters of the shadows check the Shadows page

FAB

The FAB draw function is mapped to the m.fab function so it is pretty simple to use it too

love.draw = function ()
    love.graphics.setColor(color)
    m.fab(x,y,r,depth)
end

For more info on the parameters and why you should set the color to your desired color first, check the FAB page

Colors

The color module is available through the m.color space, and all the functions are also exposed

m.color ("red","A200")
m.color.main ("cyan")
m.color.mono ("white","divider")
m.color.variations ("brown")
m.color.background ("dark")
m.color.list ()

For more info on each of this functions check the Colors page

Ripples

You can create Ripple objects through the m.ripple table with the appropriate functions

m.ripple.box(x,y,w,h,r,g,b,a,tim)
m.ripple.circle(x,y,ra,r,g,b,a,tim)
m.ripple.custom(f,fr,r,g,b,a,tim)
m.ripple.stencil(x,y,w,h,tim)

Also if for some reason you dont want to use the objects methods you can:

  • Update them through the m.ripple.update function
  • Draw them through the m.ripple.draw function
  • Start a ripple on them through the m.ripple.start function
  • Fade the active ripple on them through the m.ripple.fade function

For info on each of this functions check the Ripples page

Rounded - Rectangles

Accessing the roundrect function is simple, it is in the m.roundrect variable, the arguments are the same and the return value too.

Use it as you would do with roundrect

love.load = function ()
    m = require "material-love"
    p = m.roundrect(x,y,w,h,xr,yr,precission,{true,true,true,true})
end

love.draw = function ()
    love.graphics.polygon("fill",unpack(p))
    love.graphics.polygon("line",unpack(p))
end

For more info check the Rounded Rectangle page.

Roboto

The Roboto fonts are accessible through the m.roboto table, though you can also use it as a function as with the normal roboto table

love.graphics.setFont(m.roboto "body2")
love.graphics.setFont(m.roboto.title)

For more info check the Roboto page

Icons & DrawIcons

Icons and DrawIcons are merged into a single table, called m.icons with this four functions:

  • m.icons.get which acts as icons.get
  • m.icons.list which acts as icons.list
  • m.icons.names which acts as icons.names
  • m.icons.draw which acts as drawicon

Plus you can access the icon font through m.icons.font

Check the pages for DrawIcons and Icons for more info on these functions.

Nine Patch

The Nine Patch library can be found on the m.nine table. Using it is the same as using the nine.lua file

local PatchImage = love.graphics.newImage("material-love/images/ninepatch.png")

m.nine.convert(PatchImage,"ninepatch",true)

local PatchTable = love.filesystem.load("ninepatch.lua")()()

PatchObject = m.nine.process(PatchTable)

m.nine.draw(PatchObject,x,y,w,h,pad,image)

For more info on these functions check the Nine Patch page which explains them in detail

Image Transition

The smooth image transition that can be found on the image library can be found through m.image with both the new and draw functions.

  • m.image.new Creates a new object, with the image object which provides draw and update methods so it is easier to use it.
  • m.image.draw Handles just the draw part, so you have to provide the elapsed time.

For more info on these functions and the methods of the image object check the Image Transition page.

Loading Spinners

Loading spinners which can normally be found on the spinner library are inside m.spinner

local spin = m.spinner.new(radius,width,speed)
local ospin = m.spinner.new(oradius,owidth,ospeed)

love.update = function (dt)
    spin:update(dt)
    m.spinner.update(ospin,dt)
end

love.draw = function ()
    spin:draw(x,y)
    m.spinner.draw(ospin,ox,oy)
end

For more info on spinners and their method go to the Loading Spinners page

That is it!

I hope this can be useful to you, if you have doubts dont doubt to ask me, you can use the Issue Tracker (check the Guidelines), the LÖVE forums (which I check periodically) and you can send me a mail (you can find my e-mail here)

Clone this wiki locally