Advertisement
alestane

Funciton moduel

Dec 5th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. local stage = require "display".getCurrentStage()
  2.  
  3. local typeface = native.newFont "American Typewriter"
  4.  
  5. function splash(functions)
  6.     local self = display.newGroup()
  7.     local backdrop = display.newRect(self, 0, 0, stage.width, stage.height)
  8.     backdrop:setFillColor(47, 47, 79)
  9.    
  10.     local actionCount = 0
  11.     for _ in pairs(functions) do
  12.         actionCount = actionCount + 1
  13.     end
  14.     local maxWidth = 0
  15.     local height, pitch = stage.height * 0.1, stage.height * 0.12
  16.     local yPos = (stage.height - (actionCount - 1 ) * pitch) / 2
  17.     for text, action in pairs(functions) do
  18.         local button = display.newGroup()
  19.             self:insert(button)
  20.             button.x, button.y = stage.width / 2, yPos
  21.             yPos = yPos + pitch
  22.  
  23.             local label = display.newText(button, text, 0, 0, typeface, stage.height * 0.08)
  24.                 label:setTextColor(47, 47, 79)
  25.                 label.xOrigin, label.yOrigin = 0, 0
  26.             maxWidth = math.max(maxWidth, label.width)
  27.         button:addEventListener('tap', function(event) action(self) return true end)
  28.         button:addEventListener('touch', function(event) return true end)
  29.     end
  30.     for i=2,self.numChildren do
  31.         local button = self[i]
  32.         local fill = display.newRect(button, 0, 0, maxWidth * 1.1, height)
  33.             fill:setFillColor(.827 * 255, .694 * 255, .286 * 255)
  34.             fill.xOrigin, fill.yOrigin = 0, 0
  35.             fill:toBack()
  36.     end
  37.     self.isVisible = false
  38.    
  39.     return self
  40.  
  41. end
  42.  
  43. return splash
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement