Durazno-Canvas: A scene manager with attitude for Moai SDK

Hi again code adventurers!

With the published tutorials so far we have seen how to deal with images and we also had our first Durazno in the previous post, Durazno-Image to make our work even easier. But there’s another thing we have already seen, how to create our simulator and get ready our environment. This part of Moai could be seen as the most strange of all, as other SDK’s around don’t need it at all and run into a prebuilt simulator out-of-the-box. But hey, what if we could reduce the code to create a simulator and a viewport and also have a full-blown scene manager ready with one single line of code? Say hi to Durazno-Canvas The Durazno take on Moai’s Scene Managers.

Durazno-Canvas uses a special config.lua file to let us set our environment with a single line like this:


Once our environment is set up we can then just go to the first scene where our coding will be present with this line:

dc.gotoScene({ source = "scene1", effect = "fade" })

Notice we can apply effects to our scene changes, and we have a fair amount of them wich will be familiar to you if you are used to other Lua based SDK’s: fade, crossFade, slideLeft, slideRight, slideUp, slideDown, fromLeft, fromRight, fromTop, fromBottom, toLeft, toRight, toTop, toBottom. All available right away! You can check them all out in this short video:

For the sake of putting things in order and let you think naturally, every scene on Durazno-Canvas is expected to be in a different Lua file, and their structure should always be the same, except for your own code, here you have a template to build your own scenes:

-- Mandatory scene creation
local scene = dc.newScene()

-- Function to load everything at start
-- Don't use locals if you need to access
-- something later on SCENE.PLAY
scene.load = function()
    -- At least first layer should be inserted into
    -- the scene by passing the scene as a parameter
    -- We can then insert more layers into the first
    -- layer or the scene itself at will but we have
    -- to be sure no layer gets created on its own
    -- if we want it to be removed automatically
    layer = dc.newLayer(scene)
    partition = dc.newLayerPart(layer)

-- Function to code what happens on the scene
scene.play = function()

-- Function to unload everything at end
-- Everything into the scene tree will be
-- removed automatically
-- Decks and other resources not inserted
-- into layers should be removed and nil'd here
scene.unload = function()

-- Mandatory scene return
return scene

And that’s really it, you can check out config.lua and main.lua included with Durazno-Canvas to see what you need to get it working and learn all things you can do to have beautifully crafted scene transitions.

Want to get it? it’s free! 😉 Have fun with it!

Get it now from our Store

Leave a Reply