Skip to content

Instantly share code, notes, and snippets.

@JesterXL JesterXL/Component.lua
Last active Dec 19, 2015

Embed
What would you like to do?
Corona Invalidation Sample 1 of 2: Component.lua. Show's using enterFrame as a way to ensure drawing only once per frame.
Component = {}
function Component:new()
local component = display.newGroup()
component.classType = "Component"
component.commitDirty = false
function component:construct()
self:createChildren()
self:commitProperties()
end
function component:createChildren()end
function component:commitProperties()end
function component:invalidateProperties()
self.commitDirty = true
self.invalidateNextFrame()
end
function component:invalidate()
self.invalidateProperties()
end
function component:invalidateNextFrame()
Runtime:addEventListener("enterFrame", self)
end
function component:enterFrame()
self:validate()
end
function component:validate()
if self.commitDirty == true then
self.commitDirty = false
self:commitProperties()
end
Runtime:removeEventListener("enterFrame", self)
end
function component:validateNow(recursive)
if recursive == nil then recursive = false end
self:validate()
if recursive == true then
local child
local len = self.numChildren
while len > 0 do
child = self[len]
if child.classType == "Component" then
child:validateNow()
end
len = len - 1
end
end
end
component:construct()
return component
end
return Component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.