-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemos.lua
124 lines (109 loc) · 4.7 KB
/
demos.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
local M = {}
local shader = require("plugin.dynamic_shader")
local widget = require("widget")
local objectList = shader.getObjectListStart() -- table of objects
local methodTest
local textBack = display.newRect( display.contentCenterX, 0, display.contentWidth, 100 ) ; textBack.alpha = 0
local goDemo = true
local function startDemo( e )
if (goDemo == true) then
goDemo = false
methodTest()
end
end
local w_demo = widget.newSwitch(
{
name = "demoBut",
left = display.contentWidth - 46,
top = 16,
style = "checkbox",
id = "demoBut",
initialSwitchState = false,
onRelease = startDemo
--onPress = sliderListener
}
)
local demo_label = display.newText("Start Demo", display.contentWidth - 30, 10, 'Helvetica', 8);
demo_label:setFillColor( 0.1, 0.6, 0.8 )
------------------ Method Tests --------------
function methodTest( )
transition.to( w_demo, {delay = 500, time = 1500, alpha = 0, onComplete = function()
--w_demo:setState(false)
end} )
transition.to( demo_label, {delay = 500, time = 1500, alpha = 0} )
textBack:setFillColor( 0, 0, 0 ) ; textBack.alpha = 0.85
local delayTime, timeTime, totalTime, alphaStart, alphaEnd = 4000, 2000, 7000, 0.8, 0
local methodText = display.newText("Dynamic Shader Method Test", display.contentCenterX, 16, 'Helvetica', 12) ; --methodText.alpha = alphaStart
transition.to( methodText, {delay = delayTime, time = timeTime, alpha = alphaEnd} )
methodText:setFillColor( 0.1, 0.6, 0.8 )
local reshade = {}
local reshadeInfo = {}
local restarter = {}
local restarterInfo = {}
timer.performWithDelay( totalTime, function()
methodText.alpha = alphaStart
methodText.text = "shader.removeObject() - remove objects from Dynamic Shader\nshader.stop() - stopping the Dynamic Shader"
transition.to( methodText, {delay = delayTime, time = timeTime, alpha = alphaEnd} )
for i=1,30 do
if (objectList[i] and objectList[i].shaderInfo) then
reshade[#reshade+1] = objectList[i]
reshadeInfo[#reshadeInfo+1] = {
objectList[i].shaderInfo.map1, -- save the image file reference
objectList[i].shaderInfo.map2 -- save the normal map file reference
}
shader.removeObject(objectList[i])
end
end
shader.stop()
end )
timer.performWithDelay( totalTime * 2, function()
methodText.alpha = alphaStart
methodText.text = "return objects to the Dynamic Shader\nshader.start() - restart the Dynamic Shader"
transition.to( methodText, {delay = delayTime, time = timeTime, alpha = alphaEnd} )
for i=1,#reshade do
reshade[i].shaderInfo = {
map1 = reshadeInfo[i][1], -- reinstate image file from reshadeInfo table
map2 = reshadeInfo[i][2] -- reinstate normal map file from reshadeInfo table
}
shader.addObject(reshade[i])
end
shader.start()
end )
timer.performWithDelay( totalTime * 3, function()
methodText.alpha = alphaStart
methodText.text = "shader.destroy() - removes all objects from Dynamic Shader and calls shader.stop()"
transition.to( methodText, {delay = delayTime, time = timeTime, alpha = alphaEnd} )
for i=1,#objectList do
restarter[#restarter+1] = objectList[i]
restarterInfo[#restarterInfo+1] = {
objectList[i].shaderInfo.map1, -- save the image file reference
objectList[i].shaderInfo.map2 -- save the normal map file reference
}
end
--print( "objectList = " .. #objectList .. " / restarter List = " .. #restarter .. " - main.lua" )
shader.destroy()
end )
timer.performWithDelay( totalTime * 4, function()
methodText.alpha = alphaStart
methodText.text = "returning all objects to the Dynamic Shader\nshader.start() restart the Dynamic Shader"
transition.to( methodText, {delay = delayTime, time = timeTime, alpha = alphaEnd} )
--print( "objectList = " .. #objectList .. " / restarter List = " .. #restarter .. " - main.lua")
for i=1,#restarter do
restarter[i].shaderInfo = {
map1 = restarterInfo[i][1], -- reinstate image file from restarterInfo table
map2 = restarterInfo[i][2] -- reinstate normal map file from restarterInfo table
}
shader.addObject(restarter[i])
end
shader.start()
end )
timer.performWithDelay( totalTime * 4 + 1000, function()
transition.to( textBack, {delay = delayTime, time = timeTime, alpha = alphaEnd, onComplete = function()
transition.to( w_demo, {time = 1500, alpha = 1; onComplete = function()
goDemo = true
end} )
transition.to( demo_label, {time = 1500, alpha = 1} )
end} )
end )
end
return M