I still need help in Inserting object properly here is the code example
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 | module(..., package.seeall) function new() local localGroup = display.newGroup() require( "ice" ) local physics = require("physics") local ui = require("ui") local gameUI = require("gameUI") physics.start() physics.setGravity(0, -1) local scores = ice:loadBox( "scores" ) local high = scores:retrieve("best") print(high) display.setStatusBar( display.HiddenStatusBar ) local scoreText local score = 0 local highscore local button1 local runMode = true local spawn = true local touch = true local gameOver = false local bkg = display.newImage( "bkg.png" ) bkg.x = 160; bkg.y = 240 localGroup:insert(bkg) local score_txt =display.newText("Score: ",0,0,nil,25) score_txt.x = 160; score_txt.y = 440 score_txt:setTextColor(0,0,0) score_txt.text = "Score: ".. score localGroup:insert(score_txt) local spawnBall = function( event ) local t = event.target local phase = event.phase if touch == true then if "began" == phase then t:removeSelf() -- destroy object score = score + math.random( 1000 ) score_txt.text = "Score: ".. score end -- Stop further propagation of touch event return true end end local balls = {} local group = display.newGroup() local spawnBalloon = function() if spawn == true then ball = display.newImage( group, "balloon.png" ) ball.x = 60 + math.random( 160 ) ball.y = 550 physics.addBody( ball, { density=0.0, friction=0.1, bounce=0.1 } ) ball:addEventListener( "touch", spawnBall ) balls[#balls + 1] = ball group:insert(ball) end end timer.performWithDelay(500, spawnBalloon, -1) local function delete() for i=group.numChildren,1,-1 do local child = group[i] if group[i].y < -100 then display.remove(group[i]) -- dont know about this part, try it end end end Runtime:addEventListener("enterFrame", delete) local bt = display.newImage ("pause.png") bt.x = 290 bt.y = 30 localGroup:insert(bt) local bt2 = display.newImage ("pauseOver.png") bt2.x = bt.x bt2.y = bt.y bt2.isVisible = false localGroup:insert(bt2) local Pause = display.newText("Pause", 5, 0, "ArialRoundedMTBold", 30) Pause.x = 160 Pause.y = 110 Pause:setTextColor(0,0,0) Pause.isVisible = false localGroup:insert(Pause) local Resume = display.newText("Resume", 5, 0, "ArialRoundedMTBold", 25) Resume.x = 160 Resume.y = 190 Resume:setTextColor(0,0,0) Resume.isVisible = false localGroup:insert(Resume) local Quit = display.newText("Quit", 5, 0, "ArialRoundedMTBold", 25) Quit.x = 160 Quit.y = 270 Quit:setTextColor(0,0,0) Quit.isVisible = false localGroup:insert(Quit) --Function for start button local function done () physics.pause() spawn = false touch = false bt.isVisible = false bt2.isVisible = true Quit.isVisible = true Resume.isVisible = true Pause.isVisible = true result = timer.pause( timerID ) end bt:addEventListener("tap", done) --Function for pause button local function done () physics.start() spawn = true touch = true bt.isVisible = true bt2.isVisible = false Quit.isVisible = false Resume.isVisible = false Pause.isVisible = false result = timer.resume( timerID ) end Resume:addEventListener("tap", done) local function quit (event) if event.phase == "ended" then director:changeScene ("play") Quit.isVisible = false Resume.isVisible = false Pause.isVisible = false spawn = false end end Quit:addEventListener ("touch", quit) local count = 60 local hasRun = 0 local time = display.newText( "60", 5, 0, "ArialRoundedMTBold", 40) time:setTextColor( 0, 0, 0 ) localGroup:insert(time) local timeDelay = 700 function time:timer( event ) count = count-1 hasRun = hasRun+1 self.text = count if hasRun >= 10 then timer.cancel( event.source ) director:changeScene ("popover") end end -- Register to call t's timer method 50 times timerID = timer.performWithDelay( timeDelay, time, -1 ) local highText = display.newText("", 0,0,nil,30) highText.x = display.contentWidth/2 highText.y = display.contentHeight/2 highText.text = "HighScore: ".. scores:retrieve("best") localGroup:insert(highText) local function show_highScore() gameOver = not gameOver scores:storeIfHigher( "best", score ) scores:save() local highText = display.newText("", 0,0,nil,30) highText.x = display.contentWidth/2 highText.y = display.contentHeight/2 if score > high then highText.text = "HighScore: ".. scores:retrieve("best") else if score > high then print("new high score") highText.text = "HighScore: ".. scores:retrieve("best") end end end timer.performWithDelay(60000, show_highScore, 1) return localGroup end |
Change group:insert(ball)
to localGroup:insert(ball)
- that should do it I believe.
Let me know.
Peach :)
@peach when I do localGroup:insert(ball) I get this error you see in the see in the code when I put the time has tick 10 times change scene. When the game change scene based on the time I get the error but when I change scene when I click quit it works. So 50% of my problem is solved what could be the problem of the error appearing when the balloon changes scene based on time
If you put up some plug and play someone may be able to run through it for you and spend some of their time trying to debug.
They can't do it with this code as it requires images they don't have.
(You could also upload a zip of the project and provide a link.)
Peach :)
@Peach ok here's the link for the project
http://tinylemongames.yolasite.com/twitter-news.php
you should see it under the twitter news the file is called minigames. The lua file I'm struggling is call balloon popper.lua
@Peach thanks for your help a lot I really appreciate it. Sorry for the trouble I caused and also sorry forum.
But thanks alot. :)
I assume that means my email helped, I'm glad.
It's all OK either way :)
Peach