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