Created
November 12, 2013 00:37
-
-
Save CodeaLuis/7423283 to your computer and use it in GitHub Desktop.
States, Scenes, changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup() | |
Scene("WELCOME",firs_page) | |
Scene("GOO BYE",second_page) | |
Scene.parameter() | |
end | |
function draw() | |
background(0) | |
Scene.draw() | |
end | |
function touched(touch) | |
Scene.touched(touch) | |
end | |
--------------------- | |
--> Usamos metatable | |
--------------------- | |
Scene = {} --> Identificador para hacer llamado a las otras pantallas | |
scene = nil | |
scenes = {} | |
currentscene = nil | |
name_S = {} | |
setmetatable(Scene , { __call = function(_,name,funcion) | |
if not currentscene then | |
currentscene = 1 | |
scene = scenes[currentscene] | |
end | |
table.insert(scenes,funcion) | |
name_S[name] = #scenes | |
changes = nil | |
end}) | |
---------------------- | |
--> PARAMETER.INTEGER | |
---------------------- | |
Scene.parameter = function() parameter.integer("changes",1,#scenes,currentscene, | |
function(var) | |
Scene.change(var) end | |
) end | |
Scene.change = function(name) | |
ActualScene = nil | |
if type(name) == "string" then | |
currentscene = name_S[name] | |
end | |
ActualScene = scenes[currentscene] | |
ActualScene:init() | |
end | |
Scene.draw = function() | |
ActualScene:draw() | |
end | |
Scene.touched = function(t) | |
if ActualScene.touched then | |
ActualScene:touched(t) | |
end | |
end | |
------------------------ | |
--> SECOND CLASS | |
--> TO CALL A NEW STATE | |
------------------------ | |
firs_page = class() | |
function firs_page:init() | |
end | |
function firs_page:draw() | |
background(255) | |
end | |
function firs_page:touched(touch) | |
if touch.state == ENDED then | |
Scene.change("GOO BYE") | |
end | |
end | |
second_page = class() | |
function second_page:init() | |
end | |
function second_page:draw() | |
background(0) | |
end | |
function second_page:touched(touch) | |
if touch.state == ENDED then | |
Scene.change("WELCOME") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment