Quick Layers (ssk.display.*)

The quickLayers() function returns a single display group (layers) that contains the hierarchy as specified and that gives acess to each layer by its name, making game layering both fast and easy to implement.

Furthermore, the returned layers object provides two very useful methods:

Tip: Purges do not destroy the layer groups themselves, so the hierarchy is maintained.

Creating A Layer System


-- Create Layers For Current Scene
local layers = ssk.display.quickLayers( sceneGroup, 
   "underlay", 
   "world",
      {  "background", 
         "content", 
         "foreground" },
   "overlay" )

Produces this bottom-to-top layered group hierarchy (parentGroup is sceneGroup in this example):


\ (parentGroup)
|--\ underlay
|--\ world
   |--\ background
   |--\ content
   |--\ foreground
|--\ overlay

Using A Layer System


-- Create grey rectangle in background layer
--
local back = newRect( layers.background, centerX, centerY, 
                       { w = fullw, h = fullh, fill = _DARKGREY_ } )

-- Add a 'player' in the 'content' layer
--
local player = newImageRect( layers.content, centerX, centerY, "images/smiley.png" )

Purging A Layer


-- Create 100 cirlces in 'overlay' layer.
--
for i = 1, 100 do
   newRect( layers.overlay, centerX + math.radom( -200, 200), centerY + math.radom( -200, 200), 
            { fill = ssk.colors.randomColor() }   )
end

-- Wait 2 seconds, then purge the 'overlay' layer thus destroying all those circles.
--
timer.performWithDelay( 2000, function() layers:purge( "overlay" ) end )



RoamingGamer Copyright © Roaming Gamer, LLC. 2008-2016; All Rights Reserved