we will miss you steve jobs by dsrawat4u@gmail.com

Posted by Deepak Singh Rawat, Posted on October 14, 2011, Last updated December 6, 2011

0 votes
GitHub URL: 
http://code.google.com/p/abc-lerner-for-kids/downloads/list

This tutorial is build for a tribute to "Steve Jobs:The man behind apple"
From me(Deepak Singh Rawat) using a better way to understand movieclip action with buttons!!

For more information check my blog :-
www.anscacorona.blogspot.com

or

My youtube channel :-

www.youtube.com/user/iphonemaclover

thank you

Have fun with corona SDK
File included:-
main.lua
mainmenu.lua
loadmainmenu.lua
director.lua (taken from corona tutorials)
config.lua
build.settings
buttonLib.lua (taken from corona tutorials)
movieclip.lua (taken from corona tutorials)
ui.lua (taken from corona tutorials)

For downloading complete source code with graphics:
visit my blog link : http://anscacorona.blogspot.com/2011/10/we-miss-you-steve-job-sample-iphone.html

file main.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
-- main.lua
 --file main.lua
--To Hide the status bar
display.setStatusBar( display.HiddenStatusBar )
 
-- For Importing director.lua class
local director = require("director")
local movieclip = require("movieclip")
uiButton = require("buttonLib")
 
-- For Creating a main group
local mainGroup = display.newGroup()
 
-- Start of Main function
local function main()
 
 
        -- Adding the Group from director.lua class
        mainGroup:insert(director.directorView)
        
 
        
        
local function flash1()
        local myLogo = display.newImage("menubackground/splash.png")
        myLogo.x = 240
        myLogo.y = 160
        myLogo.alpha = 0
    transition.to( myLogo, {time=500, delay=500, alpha=1})
        transition.to( myLogo, {time=500, delay=3500, alpha=0})
end
    timer.performWithDelay(0, flash1)
 
 
local function flash2()
        local myLogo1 = display.newImage("menubackground/apple.png")
        myLogo1.x = 240
        myLogo1.y = 160
        myLogo1.alpha=0
        myLogo1.alpha = 0
        transition.to( myLogo1, {time=500, delay=500, alpha=1})
        transition.to( myLogo1, {time=500, delay=3500, alpha=0})
 end
        timer.performWithDelay(3500, flash2)
 
 
        
        local changeScene = function()
            director:changeScene("loadmainmenu", "fade")
        end
 
        timer.performWithDelay(8000, changeScene)
        --To Change scene withoutany effects
 
 
        return true
end
 
-- For Running Main Function
main()

file loadmainmenu.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
--load loadmainmenu.lua
module(..., package.seeall)
-- Main function - MUST return a display.newGroup()
function new()
        local localGroup = display.newGroup()
        
        local theTimer
        local loadingImage
        
        local showLoadingScreen = function()
                loadingImage = display.newImageRect( "menubackground/loading.png", 480, 320 )
                loadingImage.x = 240; loadingImage.y = 160
                
                local goToLevel = function()
                        loadingImage:removeSelf()
                        director:changeScene( "mainmenupage" )
                end
                
                theTimer = timer.performWithDelay( 1000, goToLevel, 1 )
        
        end
        
        showLoadingScreen()
        
        unloadMe = function()
                if theTimer then timer.cancel( theTimer );
                
                 end
                
                if loadingImage then
                        loadingImage:removeSelf()
                        loadingImage = nil
                end
        end
        
        -- MUST return a display.newGroup()
        return localGroup
end

file mainmenu.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
--load mainmenu.lua
module(..., package.seeall)
local menuGroup=display.newGroup()
local ui = require("ui")
  local movieclip = require "movieclip"
   local candle
 
function new()
local menuGroup=display.newGroup()
 -- Background
local background = display.newImage("menubackground/jobs.png")
menuGroup:insert(background)
local localGroup = display.newGroup()
 
candle = movieclip.newAnim{ "candle/candle0.png","candle/candle.png", "candle/candle1.png","candle/candle2.png","candle/candle3.png"}
candle.x=220
candle.y=220
candle.xScale=.4
candle.yScale=.4
candle:stopAtFrame(1)
 
        --- ********************************************************* ---
        ---                                                     BUTTONS                                                   ---   
        --- ********************************************************* ---
 
 
                -->> Set Up "fire" Button with required variables
 
        --Custom function to execute on began press state
        local function fireBeganFunction()
                print("fire Began State Executed")
        candle:play()
 
        end
 
        --Custom function to execute on released press state
        local function fireReleasedFunction()
                print("fire Released State Executed")
                candle:stopAtFrame(1)
                new()
        end
 
        fireBTN = movieclip.newAnim({"fire.png", "fire1.png"}) -- The sequence of images : Should contain a default and pressed state image
        fireBTN.x = 40           
        fireBTN.y = 260 
                fireBTN.xScale=.5
            fireBTN.yScale=.5                                            
        fireBTN.beganFunction = fireBeganFunction       -- The pointer to the custom function to execute on button began state (If any) Optional
        fireBTN.releasedFunction = fireReleasedFunction -- The pointer to the custom function to execute on button began state (If any) Optional
        fireBTN.removeListenerOnTouch = true            -- If true the library will automatically remove the event listener for you when it is done.
   menuGroup:insert(fireBTN)
 
        fireBTN:addEventListener("touch", uiButton.handleEvent)
 
         ------------------------------------------------------
 clean = function()
 fireBTN:removeEventListener("touch", uiButton.handleEvent)
 menuGroup:removeSelf()
end
 
        -- MUST return a display.newGroup()
        return localGroup
end

file director.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
--load director.lua
 
module(..., package.seeall)
 
-- File name - director.lua
 
directorView = display.newGroup()
currView     = display.newGroup()
nextView     = display.newGroup()
effectView   = display.newGroup()
--
local currScreen, nextScreen
local currScene, nextScene = "main", "main"
local newScene
local fxTime = 200
local safeDelay = 50
local isChangingScene = false
--
directorView:insert(currView)
directorView:insert(nextView)
directorView:insert(effectView)
--
currView.x = 0
currView.y = 0
nextView.x = display.contentWidth
nextView.y = 0
 
------------------------------------------------------------------------        
-- GET COLOR  FUNCTION
------------------------------------------------------------------------
 
local function getColor ( arg1, arg2, arg3 )
        --
        local r, g, b
        --
        if type(arg1) == "nil" then
                arg1 = "black"
        end
        --
        if string.lower(arg1) == "red" then
                r=255
                g=0
                b=0
        elseif string.lower(arg1) == "green" then
                r=0
                g=255
                b=0
        elseif string.lower(arg1) == "blue" then
                r=0
                g=0
                b=255
        elseif string.lower(arg1) == "yellow" then
                r=255
                g=255
                b=0
        elseif string.lower(arg1) == "pink" then
                r=255
                g=0
                b=255
        elseif string.lower(arg1) == "white" then
                r=255
                g=255
                b=255
        elseif type (arg1) == "number"
           and type (arg2) == "number"
           and type (arg3) == "number" then
                r=arg1
                g=arg2
                b=arg3
        else
                r=0
                g=0
                b=0
        end
        --
        return r, g, b
        --
end
 
------------------------------------------------------------------------        
-- FOR CHANGING CONTROLS
------------------------------------------------------------------------
 
-- fxTime
function director:changeFxTime ( newFxTime )
  if type(newFxTime) == "number" then
    fxTime = newFxTime
  end
end
 
-- safeDelay
function director:changeSafeDelay ( newSafeDelay )
  if type(newSafeDelay) == "number" then
    safeDelay = newSafeDelay
  end
end
 
------------------------------------------------------------------------        
-- FOR GETTING SCENES
------------------------------------------------------------------------
 
function director:getCurrScene ()
        return currScene
end
--
function director:getNextScene ()
        return nextScene
end
 
------------------------------------------------------------------------        
-- CLEAN GROUP FUNCTION
------------------------------------------------------------------------
 
local function cleanGroups ( curGroup, level )
        if curGroup.numChildren then
                while curGroup.numChildren > 0 do
                        cleanGroups ( curGroup[curGroup.numChildren], level+1 )
                end
                if level > 0 then
                        curGroup:removeSelf()
                end
        else
                curGroup:removeSelf()
                curGroup = nil
                return true
        end
end
 
------------------------------------------------------------------------        
-- CALL CLEAN FUNCTION
------------------------------------------------------------------------
 
local function callClean ( moduleName )
        if type(package.loaded[moduleName]) == "table" then
                if string.lower(moduleName) ~= "main" then
                        for k,v in pairs(package.loaded[moduleName]) do
                                if k == "clean" and type(v) == "function" then
                                        package.loaded[moduleName].clean()
                                end
                        end
                end
        end
end
 
------------------------------------------------------------------------        
-- UNLOAD SCENE
------------------------------------------------------------------------
 
local function unloadScene ( moduleName )
        if moduleName ~= "main" and type(package.loaded[moduleName]) == "table" then
                package.loaded[moduleName] = nil
                local function garbage ( event )
                        collectgarbage("collect")
                end
                garbage()
                timer.performWithDelay(fxTime,garbage)
        end
end
 
------------------------------------------------------------------------        
-- LOAD SCENE
------------------------------------------------------------------------
 
local function loadScene ( moduleName, target )
 
        -- Test parameters
        if type(moduleName) == "nil" then
                return true
        end
        if type(target) == "nil" then
                target = "next"
        end
        
        -------------------------------------
        -- Load choosed scene
        -------------------------------------
        
        -- Prev
        if string.lower(target) == "curr" then
                --
                callClean ( moduleName )
                --
                cleanGroups(currView,0)
                --
                if nextScene == moduleName then
                        cleanGroups(nextView,0)
                end
                --
                unloadScene( moduleName )
                --
                currScreen = require(moduleName).new()
                currView:insert(currScreen)
                currScene = moduleName
 
        -- Next
        else
                --
                callClean ( moduleName )
                --
                cleanGroups(nextView,0)
                --
                if currScene == moduleName then
                        cleanGroups(currView,0)
                end
                --
                unloadScene( moduleName )
                --
                nextScreen = require(moduleName).new()
                nextView:insert(nextScreen)
                nextScene = moduleName
                
        end
        
end
 
-- Load curr screen
function director:loadCurrScene ( moduleName )
        loadScene ( moduleName, "curr" )
end
 
-- Load next screen
function director:loadNextScene ( moduleName )
        loadScene ( moduleName, "next" )
end
 
------------------------------------------------------------------------
-- EFFECT ENDED
------------------------------------------------------------------------
 
local function fxEnded ( event )
 
        currView.x = 0
        currView.y = 0
        currView.xScale = 1
        currView.yScale = 1
        --
        callClean  ( currScene )
        cleanGroups( currView ,0)
        unloadScene( currScene )
        --
        currScreen = nextScreen
        currScene = newScene
        currView:insert(currScreen)
        --
        nextView.x = display.contentWidth
        nextView.y = 0
        nextView.xScale = 1
        nextView.yScale = 1
        --
        isChangingScene = false
        
end
 
------------------------------------------------------------------------        
-- CHANGE SCENE
------------------------------------------------------------------------
 
function director:changeScene(nextLoadScene, 
                              effect, 
                              arg1,
                              arg2,
                              arg3)
 
        -----------------------------------
        -- If is changing scene, return without do anything
        -----------------------------------
 
        if isChangingScene then
                return true
        else
                isChangingScene = true
        end
 
        -----------------------------------
        -- If is the same, don't change
        -----------------------------------
        
        if currScene then
                if string.lower(currScene) == string.lower(nextLoadScene) then
                        return true
                end
        end
        
        newScene = nextLoadScene
        local showFx
 
        -----------------------------------
        -- EFFECT: Move From Right
        -----------------------------------
        
        if effect == "moveFromRight" then
                        
                nextView.x = display.contentWidth
                nextView.y = 0
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { x=0, time=fxTime } )
                showFx = transition.to ( currView, { x=display.contentWidth*-1, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Over From Right
        -----------------------------------
        
        elseif effect == "overFromRight" then
        
                nextView.x = display.contentWidth
                nextView.y = 0
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { x=0, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Move From Left
        -----------------------------------
        
        elseif effect == "moveFromLeft" then
        
                nextView.x = display.contentWidth*-1
                nextView.y = 0
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { x=0, time=fxTime } )
                showFx = transition.to ( currView, { x=display.contentWidth, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
        
        -----------------------------------
        -- EFFECT: Over From Left
        -----------------------------------
        
        elseif effect == "overFromLeft" then
        
                nextView.x = display.contentWidth*-1
                nextView.y = 0
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { x=0, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Move From Top
        -----------------------------------
 
        elseif effect == "moveFromTop" then
 
                nextView.x = 0
                nextView.y = display.contentHeight*-1
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { y=0, time=fxTime } )
                showFx = transition.to ( currView, { y=display.contentHeight, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
        
        -----------------------------------
        -- EFFECT: Over From Top
        -----------------------------------
        
        elseif effect == "overFromTop" then
        
                nextView.x = 0
                nextView.y = display.contentHeight*-1
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { y=0, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Move From Bottom
        -----------------------------------
 
        elseif effect == "moveFromBottom" then
 
                nextView.x = 0
                nextView.y = display.contentHeight
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { y=0, time=fxTime } )
                showFx = transition.to ( currView, { y=display.contentHeight*-1, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
        
        -----------------------------------
        -- EFFECT: Over From Bottom
        -----------------------------------
        
        elseif effect == "overFromBottom" then
        
                nextView.x = 0
                nextView.y = display.contentHeight
                --
                loadScene (newScene)
                --
                showFx = transition.to ( nextView, { y=0, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Crossfade
        -----------------------------------
 
        elseif effect == "crossfade" then
 
                nextView.x = display.contentWidth
                nextView.y = 0
                --
                loadScene (newScene)
                --
                nextView.alpha = 0
                nextView.x = 0
                --
                showFx = transition.to ( nextView, { alpha=1, time=fxTime*2 } )
                --
                timer.performWithDelay( fxTime*2+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Fade
        -----------------------------------
        -- ARG1 = color [string]
        -----------------------------------
        -- ARG1 = red   [number]
        -- ARG2 = green [number]
        -- ARG3 = blue  [number]
        -----------------------------------
        
        elseif effect == "fade" then
        
                local r, g, b = getColor ( arg1, arg2, arg3 )
                --
                nextView.x = display.contentWidth
                nextView.y = 0
                --
                loadScene (newScene)
                --
                local fade = display.newRect( 0 - display.contentWidth, 0 - display.contentHeight, display.contentWidth * 3, display.contentHeight * 3 )
                fade.alpha = 0
                fade:setFillColor( r,g,b )
                effectView:insert(fade)
                --
                showFx = transition.to ( fade, { alpha=1.0, time=fxTime } )
                --
                timer.performWithDelay( fxTime+safeDelay, fxEnded )
                --
                local function returnFade ( event )
                
                        showFx = transition.to ( fade, { alpha=0, time=fxTime } )
                        --
                        local function removeFade ( event )
                                fade:removeSelf()
                        end
                        --
                        timer.performWithDelay( fxTime+safeDelay, removeFade )
 
                end
                --
                timer.performWithDelay( fxTime+safeDelay+1, returnFade )
                
        -----------------------------------
        -- EFFECT: Flip
        -----------------------------------
        
        elseif effect == "flip" then
        
                showFx = transition.to ( currView, { xScale=0.001, time=fxTime } )
                showFx = transition.to ( currView, { x=display.contentWidth*0.5, time=fxTime } )
                --
                loadScene (newScene)
                --
                nextView.xScale=0.001
                nextView.x=display.contentWidth*0.5
                --
                showFx = transition.to ( nextView, { xScale=1, delay=fxTime, time=fxTime } )
                showFx = transition.to ( nextView, { x=0, delay=fxTime, time=fxTime } )
                --
                timer.performWithDelay( fxTime*2+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: Down Flip
        -----------------------------------
        
        elseif effect == "downFlip" then
        
                showFx = transition.to ( currView, { xScale=0.7, time=fxTime } )
                showFx = transition.to ( currView, { yScale=0.7, time=fxTime } )
                showFx = transition.to ( currView, { x=display.contentWidth*0.15,  time=fxTime } )
                showFx = transition.to ( currView, { y=display.contentHeight*0.15, time=fxTime } )
                showFx = transition.to ( currView, { xScale=0.001, delay=fxTime, time=fxTime } )
                showFx = transition.to ( currView, { x=display.contentWidth*0.5, delay=fxTime, time=fxTime } )
                --
                loadScene (newScene)
                --
                nextView.x = display.contentWidth*0.5
                nextView.xScale=0.001
                nextView.yScale=0.7
                nextView.y=display.contentHeight*0.15
                --
                showFx = transition.to ( nextView, { x=display.contentWidth*0.15, delay=fxTime*2, time=fxTime } )
                showFx = transition.to ( nextView, { xScale=0.7, delay=fxTime*2, time=fxTime } )
                showFx = transition.to ( nextView, { xScale=1, delay=fxTime*3, time=fxTime } )
                showFx = transition.to ( nextView, { yScale=1, delay=fxTime*3, time=fxTime } )
                showFx = transition.to ( nextView, { x=0, delay=fxTime*3, time=fxTime } )
                showFx = transition.to ( nextView, { y=0, delay=fxTime*3, time=fxTime } )
                --
                timer.performWithDelay( fxTime*4+safeDelay, fxEnded )
                
        -----------------------------------
        -- EFFECT: None
        -----------------------------------
      else
                timer.performWithDelay( 0, fxEnded )
                loadScene (newScene)
        end
    return true
end

file config.lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--load config.lua
application =
{
        content =
        {
                        width = 320,
                height = 480,
                scale = "Letterbox",
                fps = 30,
                antialias = true,
                
                imageSuffix =
                                {
                                        ["@2x"] = 2,
                                },
        },
}

file buttonLib.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
--load buttonLib.lua
 
-- File name - buttonLib.lua
module(..., package.seeall)
 
-- If you are using the director class, leave this value set at true. If you don't use the director class, set it to false
local usingDirector = true
 
--Function to handle buttons
function handleEvent(event)             
                
        -- Set focus on the button
        display.getCurrentStage():setFocus(event.target)
                
        --Set up button bounds
        local bounds = event.target.contentBounds
        local x, y = event.x, event.y
        local isWithinBounds = 
        bounds.xMin <= x and bounds.xMax >= x and bounds.yMin <= y and bounds.yMax >= y
                
        if event.phase == "began" then
                --Change the displayed frame to the "Clicked / Down" image
                event.target:nextFrame()
                event.target:stopAtFrame(2)
                
                --If the touch is within the buttons bounds execute required actions
                if isWithinBounds then                  
                        --If the target has a began function execute it
                        if event.target.beganFunction then
                                event.target.beganFunction()
                        end
                end
                        
        elseif event.phase == "ended" then
                --Remove focus from the button
                display.getCurrentStage():setFocus(nil)
                
                --Change the displayed frame to the "Default" image
                event.target:previousFrame()
                event.target:stopAtFrame(1)
                
                --If the touch is within the buttons bounds execute required actions
                if isWithinBounds then                  
                        --Play the sound upon click (if it exists)
                        if event.target.sound then
                                audio.play(event.target.sound)
                        else
                                print("Error : Either the sound doesn't exist or you have not specified a sound to play on touch")
                        end
                        
                        --If the target has a released function execute it
                        if event.target.releasedFunction then
                                event.target.releasedFunction()
                        end
                        
                        --Remove the button listener to prevent crashing the game upon scene change (when using director class)
                        if event.target.removeListenerOnTouch == true then
                                event.target:removeEventListener("touch", handleEvent)
                        end             
                                
                        -- Change director scene or execute required action (if using it)
                        if usingDirector == true then
                                if event.target.sceneChangesTo and event.target.sceneChangesWithEffect then
                                        director:changeScene(event.target.sceneChangesTo, event.target.sceneChangesWithEffect)
                                end
                        end
                end
        end
end

file movieclip.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
--load movieclip.lua
-- 
-- Abstract: animated sprite or "movieclip" library
-- This library assembles animation sequences from individual image files. For more advanced 
-- texture memory handling, see the "sprite sheet" feature in Corona Game Edition.
--
-- Version: 2.01
 
-- Disclaimer: IMPORTANT:  This ANSCA software is supplied to you by ANSCA Inc.
-- ("ANSCA") in consideration of your agreement to the following terms, and your
-- use, installation, modification or redistribution of this ANSCA software
-- constitutes acceptance of these terms.  If you do not agree with these terms,
-- please do not use, install, modify or redistribute this ANSCA software.
-- 
-- In consideration of your agreement to abide by the following terms, and subject
-- to these terms, ANSCA grants you a personal, non-exclusive license, under
-- ANSCA's copyrights in this original ANSCA software (the "ANSCA Software"), to
-- use, reproduce, modify and redistribute the ANSCA Software, with or without
-- modifications, in source and/or binary forms; provided that if you redistribute
-- the ANSCA Software in its entirety and without modifications, you must retain
-- this notice and the following text and disclaimers in all such redistributions
-- of the ANSCA Software.
-- Neither the name, trademarks, service marks or logos of ANSCA Inc. may be used
-- to endorse or promote products derived from the ANSCA Software without specific
-- prior written permission from ANSCA.  Except as expressly stated in this notice,
-- no other rights or licenses, express or implied, are granted by ANSCA herein,
-- including but not limited to any patent rights that may be infringed by your
-- derivative works or by other works in which the ANSCA Software may be
-- incorporated.
-- 
-- The ANSCA Software is provided by ANSCA on an "AS IS" basis.  ANSCA MAKES NO
-- WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
-- WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-- PURPOSE, REGARDING THE ANSCA SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
-- COMBINATION WITH YOUR PRODUCTS.
-- 
-- IN NO EVENT SHALL ANSCA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-- ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
-- DISTRIBUTION OF THE ANSCA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
-- CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
-- ANSCA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--
-- Copyright (C) 2010 ANSCA Inc. All Rights Reserved.
 
-- movieclip.lua (a convenience library for assembling animated sprites from separate images)
 
 
-- File name - movieclip.lua
 
module(..., package.seeall)
 
local movMFloor = math.floor
local movMCeil = math.ceil
 
 
function newAnim (imageTable)
 
        -- Set up graphics
        local g = display.newGroup()
        local animFrames = {}
        local animLabels = {}
        local limitX, limitY, transpose
        local startX, startY
 
        local i = 1
        while imageTable[i] do
                animFrames[i] = display.newImage(imageTable[i]);
                g:insert(animFrames[i], true)
                animLabels[i] = i -- default frame label is frame number
                animFrames[i].isVisible = false
                i = i + 1
        end
 
        -- show first frame by default
        animFrames[1].isVisible = true
 
        -------------------------
        -- Define private methods
        
        local currentFrame = 1
        local totalFrames = #animFrames
        local startFrame = 1
        local endFrame = #animFrames
        local loop = 0
        local loopCount = 0
        local remove = false
        local dragBounds = nil
        local dragLeft, dragTop, dragWidth, dragHeight
        
        local animSpeed = 1.0
        local animTime = 1.0
 
        -- flag to distinguish initial default case (where no sequence parameters are submitted)
        local inSequence = false
        
        local function resetDefaults()
                currentFrame = 1
                startFrame = 1
                animTime = 1.0
                endFrame = #animFrames
                loop = 0
                loopCount = 0
                remove = false
        end
        
        local function resetReverseDefaults()
                currentFrame = #animFrames
                startFrame = #animFrames
                animTime = #animFrames
                endFrame = 1
                loop = 0
                loopCount = 0
                remove = false
        end
        
        local function nextFrame( self, event )
                animFrames[currentFrame].isVisible = false
                 animTime = animTime + animSpeed
                currentFrame = movMFloor(animTime)
                
                if (currentFrame == endFrame + 1) then
                        if (loop > 0) then
                                loopCount = loopCount + 1
 
                                if (loopCount == loop) then
                                        -- stop looping
                                        currentFrame = currentFrame - 1
                                        animTime = currentFrame
                                        animFrames[currentFrame].isVisible = true
                                        Runtime:removeEventListener( "enterFrame", self )
 
                                        if (remove) then
                                                 self.parent:remove(self)
                                        end
 
                                else
                                        currentFrame = startFrame
                                        animTime = startFrame
                                        animFrames[currentFrame].isVisible = true
                                end
 
                        else
                                currentFrame = startFrame
                                animTime = startFrame
                                animFrames[currentFrame].isVisible = true
                        end
                        
                elseif (currentFrame > #animFrames) then
                        currentFrame = 1
                        animTime = 1.0
                        animFrames[currentFrame].isVisible = true
                        
                else
                        animFrames[currentFrame].isVisible = true
                        
                end
        end
 
        
        local function prevFrame( self, event )
                animFrames[currentFrame].isVisible = false
                 animTime = animTime - animSpeed
                currentFrame = movMCeil(animTime)
                
                if (currentFrame == endFrame - 1) then
                        if (loop > 0) then
                                loopCount = loopCount + 1
 
                                if (loopCount == loop) then 
                                        -- stop looping
                                        currentFrame = currentFrame + 1
                                        animTime = currentFrame
                                        animFrames[currentFrame].isVisible = true
                                        Runtime:removeEventListener( "enterFrame", self )
 
                                        if (remove) then
                                                -- delete self
                                                self.parent:remove(self)
                                        end
 
                                else
                                        currentFrame = startFrame
                                        animTime = startFrame
                                        animFrames[currentFrame].isVisible = true
                                end
 
                        else
                                currentFrame = startFrame
                                animTime = startFrame
                                animFrames[currentFrame].isVisible = true
                        end
                        
                elseif (currentFrame < 1) then
                        currentFrame = #animFrames
                        animTime = #animFrames
                        animFrames[currentFrame].isVisible = true
                        
                else
                        animFrames[currentFrame].isVisible = true
                        
                end
        end
        
        
        local function dragMe(self, event)
                local onPress = self._onPress
                local onDrag = self._onDrag
                local onRelease = self._onRelease
        
                if event.phase == "began" then
                        display.getCurrentStage():setFocus( self )
                        startX = g.x
                        startY = g.y
                        
                        if onPress then
                                result = onPress( event )
                        end
                        
                elseif event.phase == "moved" then
        
                        if transpose == true then
                                -- Note: "transpose" is deprecated now that Corona supports native landscape mode
                                -- dragBounds is omitted in transposed mode, but feel free to implement it
                                if limitX ~= true then
                                        g.x = startX - (event.yStart - event.y)
                                end
                                if limitY ~= true then
                                        g.y = startY + (event.xStart - event.x)
                                end
                        else
                                if limitX ~= true then
                                        g.x = startX - (event.xStart - event.x)
                                        if (dragBounds) then
                                                if (g.x < dragLeft) then g.x = dragLeft end
                                                if (g.x > dragLeft + dragWidth) then g.x = dragLeft + dragWidth end
                                        end
                                end
                                if limitY ~= true then
                                        g.y = startY - (event.yStart - event.y)
                                        if (dragBounds) then
                                                if (g.y < dragTop) then g.y = dragTop end
                                                if (g.y > dragTop + dragHeight) then g.y = dragTop + dragHeight end
                                        end
                                end
                        end
 
                        if onDrag then
                                result = onDrag( event )
                        end
                                
                elseif event.phase == "ended" then
                        display.getCurrentStage():setFocus( nil )
 
                        if onRelease then
                                result = onRelease( event )
                        end
                        
                end
                
                -- stop touch from falling through to objects underneath
                return true
        end
 
 
        ------------------------
        -- Define public methods
 
        function g:setSpeed(s)
                animSpeed = s
        end
 
        function g:enterFrame( event )
                self:repeatFunction( event )
        end
 
        function g:play( params )
                Runtime:removeEventListener( "enterFrame", self )
 
                if ( params ) then
                        -- if any parameters are submitted, assume this is a new sequence and reset all default values
                        animFrames[currentFrame].isVisible = false
                        resetDefaults()                         
                        inSequence = true
                        -- apply optional parameters (with some boundary and type checking)
                        --if ( params.startFrame and type(params.startFrame) == "number" ) then startFrame=params.startFrame end
                        if ( params.startFrame and type(params.startFrame) == "number" ) then 
                                startFrame=params.startFrame
                                animTime = startFrame
                        end
                        if ( startFrame > #animFrames or startFrame < 1 ) then startFrame = 1 end
                
                        if ( params.endFrame and type(params.endFrame) == "number" ) then endFrame=params.endFrame end
                        if ( endFrame > #animFrames or endFrame < 1 ) then endFrame = #animFrames end
                
                        if ( params.loop and type(params.loop) == "number" ) then loop=params.loop end
                        if ( loop < 0 ) then loop = 0 end
                        
                        if ( params.remove and type(params.remove) == "boolean" ) then remove=params.remove end
                        loopCount = 0
                else
                        if (not inSequence) then
                                -- use default values
                                startFrame = 1
                                animTime = startFrame
                                endFrame = #animFrames
                                loop = 0
                                loopCount = 0
                                remove = false
                        end                     
                end
                
                currentFrame = startFrame
                animFrames[startFrame].isVisible = true 
                
                self.repeatFunction = nextFrame
                Runtime:addEventListener( "enterFrame", self )
        end
        
        
        function g:reverse( params )
                Runtime:removeEventListener( "enterFrame", self )
                
                if ( params ) then
                        -- if any parameters are submitted, assume this is a new sequence and reset all default values
                        animFrames[currentFrame].isVisible = false
                        resetReverseDefaults()
                        inSequence = true
                        -- apply optional parameters (with some boundary and type checking)
                        --if ( params.startFrame and type(params.startFrame) == "number" ) then startFrame=params.startFrame end
                        if ( params.startFrame and type(params.startFrame) == "number" ) then 
                                startFrame=params.startFrame
                                animTime = startFrame
                        end
                        if ( startFrame > #animFrames or startFrame < 1 ) then startFrame = #animFrames end
                
                        if ( params.endFrame and type(params.endFrame) == "number" ) then endFrame=params.endFrame end
                        if ( endFrame > #animFrames or endFrame < 1 ) then endFrame = 1 end
                
                        if ( params.loop and type(params.loop) == "number" ) then loop=params.loop end
                        if ( loop < 0 ) then loop = 0 end
                
                        if ( params.remove and type(params.remove) == "boolean" ) then remove=params.remove end
                else
                        if (not inSequence) then
                                -- use default values
                                startFrame = #animFrames
                                animTime = startFrame
                                endFrame = 1
                                loop = 0
                                loopCount = 0
                                remove = false
                        end
                end
                
                currentFrame = startFrame
                animFrames[startFrame].isVisible = true 
                
                self.repeatFunction = prevFrame
                Runtime:addEventListener( "enterFrame", self )
        end
 
        
        function g:nextFrame()
                -- stop current sequence, if any, and reset to defaults
                Runtime:removeEventListener( "enterFrame", self )
                inSequence = false
                
                animFrames[currentFrame].isVisible = false
                currentFrame = currentFrame + 1
                if ( currentFrame > #animFrames ) then
                        currentFrame = 1
                end
                animFrames[currentFrame].isVisible = true
        end
        
        
        function g:previousFrame()
                -- stop current sequence, if any, and reset to defaults
                Runtime:removeEventListener( "enterFrame", self )
                inSequence = false
                
                animFrames[currentFrame].isVisible = false
                currentFrame = currentFrame - 1
                if ( currentFrame < 1 ) then
                        currentFrame = #animFrames
                end
                animFrames[currentFrame].isVisible = true
        end
 
        function g:currentFrame()
                return currentFrame
        end
        
        function g:totalFrames()
                return totalFrames
        end
        
        function g:stop()
                Runtime:removeEventListener( "enterFrame", self )
        end
 
        function g:stopAtFrame(label)
                -- This works for either numerical indices or optional text labels
                if (type(label) == "number") then
                        Runtime:removeEventListener( "enterFrame", self )
                        animFrames[currentFrame].isVisible = false
                        currentFrame = label
                        animFrames[currentFrame].isVisible = true
                        
                elseif (type(label) == "string") then
                        for k, v in next, animLabels do
                                if (v == label) then
                                        Runtime:removeEventListener( "enterFrame", self )
                                        animFrames[currentFrame].isVisible = false
                                        currentFrame = k
                                        animFrames[currentFrame].isVisible = true
                                end
                        end
                end
        end
 
        
        function g:playAtFrame(label)
                -- This works for either numerical indices or optional text labels
                if (type(label) == "number") then
                        Runtime:removeEventListener( "enterFrame", self )
                        animFrames[currentFrame].isVisible = false
                        currentFrame = label
                        animFrames[currentFrame].isVisible = true
                        
                elseif (type(label) == "string") then
                        for k, v in next, animLabels do
                                if (v == label) then
                                        Runtime:removeEventListener( "enterFrame", self )
                                        animFrames[currentFrame].isVisible = false
                                        currentFrame = k
                                        animFrames[currentFrame].isVisible = true
                                end
                        end
                end
                self.repeatFunction = nextFrame
                Runtime:addEventListener( "enterFrame", self )
        end
 
 
        function g:setDrag( params )
                if ( params ) then
                        if params.drag == true then
                                limitX = (params.limitX == true)
                                limitY = (params.limitY == true)
                                transpose = (params.transpose == true)
                                dragBounds = nil
                                
                                if ( params.onPress and ( type(params.onPress) == "function" ) ) then
                                        g._onPress = params.onPress
                                end
                                if ( params.onDrag and ( type(params.onDrag) == "function" ) ) then
                                        g._onDrag = params.onDrag
                                end
                                if ( params.onRelease and ( type(params.onRelease) == "function" ) ) then
                                        g._onRelease = params.onRelease
                                end
                                if ( params.bounds and ( type(params.bounds) == "table" ) ) then
                                        dragBounds = params.bounds
                                        dragLeft = dragBounds[1]
                                        dragTop = dragBounds[2]
                                        dragWidth = dragBounds[3]
                                        dragHeight = dragBounds[4]
                                end
                                
                                g.touch = dragMe
                                g:addEventListener( "touch", g )
                                
                        else
                                g:removeEventListener( "touch", g )
                                dragBounds = nil
                                
                        end
                end
        end
 
 
        -- Optional function to assign text labels to frames
        function g:setLabels(labelTable)
                for k, v in next, labelTable do
                        if (type(k) == "string") then
                                animLabels[v] = k
                        end
                end             
        end
        
        -- Return instance of anim
        return g
 
end

file ui.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
--load ui.lua
 module(..., package.seeall)
 
-----------------
-- Helper function for newButton utility function below
local function newButtonHandler( self, event )
 
        local result = true
 
        local default = self[1]
        local over = self[2]
        
        -- General "onEvent" function overrides onPress and onRelease, if present
        local onEvent = self._onEvent
        
        local onPress = self._onPress
        local onRelease = self._onRelease
 
        local buttonEvent = {}
        if (self._id) then
                buttonEvent.id = self._id
        end
 
        local phase = event.phase
        if "began" == phase then
                if over then 
                        default.isVisible = false
                        over.isVisible = true
                end
 
                if onEvent then
                        buttonEvent.phase = "press"
                        result = onEvent( buttonEvent )
                elseif onPress then
                        result = onPress( event )
                end
 
                -- Subsequent touch events will target button even if they are outside the stageBounds of button
                display.getCurrentStage():setFocus( self, event.id )
                self.isFocus = true
                
        elseif self.isFocus then
                local bounds = self.stageBounds
                local x,y = event.x,event.y
                local isWithinBounds = 
                        bounds.xMin <= x and bounds.xMax >= x and bounds.yMin <= y and bounds.yMax >= y
 
                if "moved" == phase then
                        if over then
                                -- The rollover image should only be visible while the finger is within button's stageBounds
                                default.isVisible = not isWithinBounds
                                over.isVisible = isWithinBounds
                        end
                        
                elseif "ended" == phase or "cancelled" == phase then 
                        if over then 
                                default.isVisible = true
                                over.isVisible = false
                        end
                        
                        if "ended" == phase then
                                -- Only consider this a "click" if the user lifts their finger inside button's stageBounds
                                if isWithinBounds then
                                        if onEvent then
                                                buttonEvent.phase = "release"
                                                result = onEvent( buttonEvent )
                                        elseif onRelease then
                                                result = onRelease( event )
                                        end
                                end
                        end
                        
                        -- Allow touch events to be sent normally to the objects they "hit"
                        display.getCurrentStage():setFocus( self, nil )
                        self.isFocus = false
                end
        end
 
        return result
end
 
 
---------------
-- Button class
 
function newButton( params )
        local button, defaultSrc , defaultX , defaultY , overSrc , overX , overY , size, font, textColor, offset
        
        if params.defaultSrc then
                button = display.newGroup()
                default = display.newImageRect ( params.defaultSrc , params.defaultX , params.defaultY )
                button:insert( default, true )
        end
        
        if params.overSrc then
                over = display.newImageRect ( params.overSrc , params.overX , params.overY )
                over.isVisible = false
                button:insert( over, true )
        end
        
        -- Public methods
        function button:setText( newText )
        
                local labelText = self.text
                if ( labelText ) then
                        labelText:removeSelf()
                        self.text = nil
                end
 
                local labelShadow = self.shadow
                if ( labelShadow ) then
                        labelShadow:removeSelf()
                        self.shadow = nil
                end
 
                local labelHighlight = self.highlight
                if ( labelHighlight ) then
                        labelHighlight:removeSelf()
                        self.highlight = nil
                end
                
                if ( params.size and type(params.size) == "number" ) then size=params.size else size=20 end
                if ( params.font ) then font=params.font else font=native.systemFontBold end
                if ( params.textColor ) then textColor=params.textColor else textColor={ 255, 255, 255, 255 } end
                
                size = size * 2
                
                -- Optional vertical correction for fonts with unusual baselines (I'm looking at you, Zapfino)
                if ( params.offset and type(params.offset) == "number" ) then offset=params.offset else offset = 0 end
                
                if ( params.emboss ) then
                        -- Make the label text look "embossed" (also adjusts effect for textColor brightness)
                        local textBrightness = ( textColor[1] + textColor[2] + textColor[3] ) / 3
                        
                        labelHighlight = display.newText( newText, 0, 0, font, size )
                        if ( textBrightness > 127) then
                                labelHighlight:setTextColor( 255, 255, 255, 20 )
                        else
                                labelHighlight:setTextColor( 255, 255, 255, 140 )
                        end
                        button:insert( labelHighlight, true )
                        labelHighlight.x = labelHighlight.x + 1.5; labelHighlight.y = labelHighlight.y + 1.5 + offset
                        self.highlight = labelHighlight
 
                        labelShadow = display.newText( newText, 0, 0, font, size )
                        if ( textBrightness > 127) then
                                labelShadow:setTextColor( 0, 0, 0, 128 )
                        else
                                labelShadow:setTextColor( 0, 0, 0, 20 )
                        end
                        button:insert( labelShadow, true )
                        labelShadow.x = labelShadow.x - 1; labelShadow.y = labelShadow.y - 1 + offset
                        self.shadow = labelShadow
                        
                        labelHighlight.xScale = .5; labelHighlight.yScale = .5
                        labelShadow.xScale = .5; labelShadow.yScale = .5
                end
                
                labelText = display.newText( newText, 0, 0, font, size )
                labelText:setTextColor( textColor[1], textColor[2], textColor[3], textColor[4] )
                button:insert( labelText, true )
                labelText.y = labelText.y + offset
                self.text = labelText
                
                labelText.xScale = .5; labelText.yScale = .5
        end
        
        if params.text then
                button:setText( params.text )
        end
        
        if ( params.onPress and ( type(params.onPress) == "function" ) ) then
                button._onPress = params.onPress
        end
        if ( params.onRelease and ( type(params.onRelease) == "function" ) ) then
                button._onRelease = params.onRelease
        end
        
        if (params.onEvent and ( type(params.onEvent) == "function" ) ) then
                button._onEvent = params.onEvent
        end
        
        -- set button to active (meaning, can be pushed)
        button.isActive = true
        
        -- Set button as a table listener by setting a table method and adding the button as its own table listener for "touch" events
        button.touch = newButtonHandler
        button:addEventListener( "touch", button )
 
        if params.x then
                button.x = params.x
        end
        
        if params.y then
                button.y = params.y
        end
        
        if params.id then
                button._id = params.id
        end
 
        return button
end
 
 
--------------
-- Label class
 
function newLabel( params )
        local labelText
        local size, font, textColor, align
        local t = display.newGroup()
        
        if ( params.bounds ) then
                local bounds = params.bounds
                local left = bounds[1]
                local top = bounds[2]
                local width = bounds[3]
                local height = bounds[4]
        
                if ( params.size and type(params.size) == "number" ) then size=params.size else size=20 end
                if ( params.font ) then font=params.font else font=native.systemFontBold end
                if ( params.textColor ) then textColor=params.textColor else textColor={ 255, 255, 255, 255 } end
                if ( params.offset and type(params.offset) == "number" ) then offset=params.offset else offset = 0 end
                if ( params.align ) then align = params.align else align = "center" end
                
                if ( params.text ) then
                        labelText = display.newText( params.text, 0, 0, font, size )
                        labelText:setTextColor( textColor[1], textColor[2], textColor[3], textColor[4] )
                        t:insert( labelText )
                        -- TODO: handle no-initial-text case by creating a field with an empty string?
        
                        if ( align == "left" ) then
                                labelText.x = left + labelText.stageWidth * 0.5
                        elseif ( align == "right" ) then
                                labelText.x = (left + width) - labelText.stageWidth * 0.5
                        else
                                labelText.x = ((2 * left) + width) * 0.5
                        end
                end
                
                labelText.y = top + labelText.stageHeight * 0.5
 
                -- Public methods
                function t:setText( newText )
                        if ( newText ) then
                                labelText.text = newText
                                
                                if ( "left" == align ) then
                                        labelText.x = left + labelText.stageWidth / 2
                                elseif ( "right" == align ) then
                                        labelText.x = (left + width) - labelText.stageWidth / 2
                                else
                                        labelText.x = ((2 * left) + width) / 2
                                end
                        end
                end
                
                function t:setTextColor( r, g, b, a )
                        local newR = 255
                        local newG = 255
                        local newB = 255
                        local newA = 255
 
                        if ( r and type(r) == "number" ) then newR = r end
                        if ( g and type(g) == "number" ) then newG = g end
                        if ( b and type(b) == "number" ) then newB = b end
                        if ( a and type(a) == "number" ) then newA = a end
 
                        labelText:setTextColor( r, g, b, a )
                end
        end
        
        -- Return instance (as display group)
        return t
end

file build.settings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- build.settings
 
settings =
{
        orientation =
        {
                default = "landscapeRight",
                                content = "landscapeRight",
                                supported =
                                        {
                                                        "landscapeRight"
                                        },
        },
 
        iphone =
        {
                plist =
                {
                        UIApplicationExitsOnSuspend = false                        
 
                },
        }
}

Thanks have fun with corona


Replies

Ninja Pig Studios's picture
Ninja Pig Studios
User offline. Last seen 15 hours 54 min ago. Offline
Joined: 26 Jan 2011

Um yeah...sorry no vote for you.

mkelly's picture
mkelly
User offline. Last seen 5 weeks 2 days ago. Offline
Joined: 4 Feb 2012

well you have my vote anyway for what it's worth. thanks for this excellent example!!!

Deepak Singh Rawat's picture
Deepak Singh Rawat
User offline. Last seen 14 weeks 4 days ago. Offline
Joined: 13 Apr 2011

Thanks... As Steve Job is the man who made unexpected things possible...