Wiki
Clone wikiCore / tabCode
Distributing Code Over Tabs
An example of how to distribute code over a number of tabs (provided by John Millard/Simeon Saens).
John Millard has done this with the Physics Lab Example Project. There, he has a number of tabs (Test1, Test2, Test3, ...) and in the Main file he creates a parameter,integer()
, as you drag the slider the physics scene changes from Test1 to Test2 and so on. There are a number of ways you could do this, the most basic would be:
Test1 - draws a rect
-- Test 1 Scene
Test1 = class()
function Test1:init()
-- init scene (treat this as if it's setup() in Main)
end
function Test1:draw()
-- draw a rect
background(0)
fill(255,0,0)
rect(0,0,100,100)
end
function Test1:touched(touch)
--handle touches
end
Test2 - draws an ellipse
-- Test 2 Scene
Test2 = class()
function Test2:init()
-- init scene (treat this as if it's setup() in Main)
end
function Test2:draw()
-- draw an ellipse
background(0)
fill(0,255,0)
ellipse(50,50,100,100)
end
function Test2:touched(touch)
--handle touches
end
Main - switch between scenes
-- Main
function setup()
scenes = {}
scenes[1] = Test1()
scenes[2] = Test2()
-- SceneIndex parameter from 1 to number of scenes
parameter.integer("SceneIndex",1,#scenes)
end
function draw()
scenes[SceneIndex]:draw()
end
function touched(touch)
scenes[SceneIndex]:touched(touch)
end
Updated