Thu, 22 Aug 2013 19:50:12 +0200
Flush progress with initial commit, improve application.
1 -- Top of scene
2 --print('This is a new scene!')
4 -- Initiate scene management
5 local sceneloc = director:createScene()
6 sceneloc.name = 'Scene: Intro'
8 -- Constants calculated
9 local dsw = director.displayWidth
10 local dsh = director.displayHeight
11 local dmw = director.displayCenterX
12 local dmh = director.displayCenterY
14 -- Instantiate common fonts
15 local fontSegoe = director:createFont('fonts/SegoeUI-64pt_bold.fnt')
16 local fontArial = director:createFont('fonts/Arial-96pt_bold.fnt')
18 function sceneloc:setUp(event)
19 dbg.print('sceneloc:setUp')
21 -- Prepare playing streams
22 --audio:stopStream()
23 if not audio:isStreamPlaying() then
24 audio:loadStream('sounds/vapour.mp3')
25 audio:playStream('sounds/vapour.mp3', true)
26 end
28 -- Print background
29 local rectBack = director:createRectangle({
30 x=0, y=0,
31 w=dsw, h=dsh,
32 strokeWidth=0,
33 color={10, 74, 134}, alpha=1})
35 -- Initialize heading labels
36 local labTitle = director:createLabel({
37 x=0, y=-fontArial.height*1.5/6,
38 hAlignment='centre', vAlignment='top',
39 font=fontArial,
40 text='Astrokaat Instructions',
41 color={0xe0, 0xe0, 0xff}
42 })
44 -- Initialize heading buttons
45 local butInfo = director:createSprite(dsw-fontSegoe.height, dsh-fontArial.height*1.5/6, 'images/butinfo.png')
46 butInfo.xAnchor = 1
47 butInfo.yAnchor = 1
49 -- Initialize body text labels
50 local rectalph = director:createRectangle(fontSegoe.height, fontSegoe.height, dsw - fontSegoe.height * 2, dsh - fontArial.height * 2.25)
51 rectalph.color = color.black
52 rectalph.color.a = 64
53 local labCont = director:createLabel({
54 x=fontSegoe.height*2, y=-fontSegoe.height*3.25,
55 w=dsw-fontSegoe.height*3, h=0,
56 hAlignment='left', vAlignment='top',
57 font=fontSegoe,
58 text='Keep Astrokaat alive by maintaining her health. Eat flying food while avoiding space obstacles. Direct Astrokaat about by pushing on the screen.'
59 })
61 -- Initialize body buttons
62 local butRules = director:createSprite(fontSegoe.height*2, fontSegoe.height*2, 'images/butrules.png')
63 local butStart = director:createSprite(dsw-fontSegoe.height*2, fontSegoe.height*2, 'images/butstart.png')
64 butStart.xAnchor = 1
65 butStart.yAnchor = 0
67 -- Good transitions: slideInL/R, shrinkGrow, crossFade, fadeTR/BL, pageTurn, progressVertical
68 local transoptl = {transitionType = 'slideInL', transitionTime = 0.5}
69 local transoptr = {transitionType = 'slideInR', transitionTime = 0.5}
70 local transoptt = {transitionType = 'slideInT', transitionTime = 0.5}
71 local transoptb = {transitionType = 'slideInB', transitionTime = 0.5}
73 -- Implement event handlers
74 function butInfo:touch(event)
75 if event.phase == 'began' then
76 table.insert(nodeLastscene, director:getCurrentScene())
77 table.insert(nodeLasttrans, transoptb)
78 director:moveToScene(sceneAbout, transoptt)
79 end
80 return true
81 end
82 butInfo:addEventListener('touch', butInfo)
84 function butRules:touch(event)
85 if event.phase == 'began' then
86 table.insert(nodeLastscene, director:getCurrentScene())
87 table.insert(nodeLasttrans, transoptr)
88 director:moveToScene(sceneRules, transoptl)
89 end
90 return true
91 end
92 butRules:addEventListener('touch', butRules)
94 function butStart:touch(event)
95 if event.phase == 'began' then
96 table.insert(nodeLastscene, director:getCurrentScene())
97 table.insert(nodeLasttrans, transoptl)
98 director:moveToScene(sceneBegin, transoptr)
99 end
100 return true
101 end
102 butStart:addEventListener('touch', butStart)
103 end
105 function sceneloc:tearDown(event)
106 dbg.print('sceneloc:tearDown')
107 --self.releaseResources()
108 --self.<obj-here> = self.<obj-here>:removeFromParent()
109 --self.obj0:removeFromParent()
110 --self.obj1:removeFromParent()
111 --self.obj0 = nil
112 --self.obj1 = nil
113 end
115 function sceneloc:enterPreTransition(event)
116 dbg.print('sceneloc:enterPreTransition')
117 end
119 function sceneloc:enterPostTransition(event)
120 dbg.print('sceneloc:enterPostTransition')
121 end
123 function sceneloc:exitPreTransition(event)
124 dbg.print('sceneloc:exitPreTransition')
125 end
127 function sceneloc:exitPostTransition(event)
128 dbg.print('sceneloc:exitPostTransition')
129 end
131 sceneloc:addEventListener({'setUp', 'tearDown', 'enterPreTransition',
132 'enterPostTransition', 'exitPreTransition', 'exitPostTransition'}, sceneloc)
134 return sceneloc