SHOW:
|
|
- or go back to the newest paste.
| 1 | -- home.lua | |
| 2 | local backToButton = containerClass.new(sceneGroup) | |
| 3 | print(backToButton.swapColorsOnTap) -- This returns false | |
| 4 | backToButton.swapColorsOnTap = true | |
| 5 | print(backToButton.swapColorsOnTap) -- This returns true | |
| 6 | ||
| 7 | ||
| 8 | -- container.lua | |
| 9 | require "lib.utils" | |
| 10 | local boxClass = require("classes.box")
| |
| 11 | ||
| 12 | local _M = {}
| |
| 13 | ||
| 14 | -- Default values for the feature class | |
| 15 | local self = {
| |
| 16 | -- Public Variables | |
| 17 | contains = {}, -- a table of boxes
| |
| 18 | popUps = {}, -- a table of containers
| |
| 19 | popUpsVisible = false, | |
| 20 | swapColorsOnTap = false, | |
| 21 | ||
| 22 | -- Private Variables | |
| 23 | parent = nil, | |
| 24 | group = nil, | |
| 25 | class = "Container", | |
| 26 | isType = "Unknown", | |
| 27 | } | |
| 28 | ||
| 29 | - | function self.onTap (event) |
| 29 | + | function self:tap(event) |
| 30 | - | print ("container was tapped")
|
| 30 | + | print("container was tapped")
|
| 31 | print(self.swapColorsOnTap) -- This always returns false | |
| 32 | if self.swapColorsOnTap then | |
| 33 | print ("swapColorsonTap is true!")
| |
| 34 | - | for i = 1, #contains do |
| 34 | + | for i = 1, #self.contains do |
| 35 | print("got a box")
| |
| 36 | - | if contains[i].class == "Box" then contains[i]:swapColors() end |
| 36 | + | if self.contains[i].class == "Box" then self.contains[i]:swapColors() end |
| 37 | end | |
| 38 | end | |
| 39 | return true | |
| 40 | end | |
| 41 | ||
| 42 | function self:init(parentGroup) | |
| 43 | - | print ("Initializing the container")
|
| 43 | + | print("Initializing the container")
|
| 44 | -- Create a group for the container and insert it into the parent group | |
| 45 | self.group = display.newGroup() | |
| 46 | - | parentGroup:insert( self.group ) |
| 46 | + | parentGroup:insert(self.group) |
| 47 | - | self.group:addEventListener( "tap", self.onTap ) |
| 47 | + | self.group:addEventListener("tap")
|
| 48 | end | |
| 49 | ||
| 50 | -- Create a new instance of the feature class, use the options if provided. | |
| 51 | function _M.new(group) | |
| 52 | local newContainer = table.deepcopy(self) | |
| 53 | newContainer:init(group) | |
| 54 | return newContainer | |
| 55 | end | |
| 56 | ||
| 57 | return _M |