Hi,
Im using director class version 1.3, the problem is that i have one block of code that does not work once i have director class in and the main.lua says to change to level1 wich is the file the code is in. I had a lot more code before and everything works fine except the code below, i can't figure out why?
Everything works fine until i put it into level1.lua, it just has no effect. Anyone know why?
THANKS.
The code that is not working in level1.lua , the main.lua says to change to level1.
-- I can't figure out why it does not work...
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 | local i = 1 local tempLine local ractgangle_hit = {} local prevX , prevY local function runTouch(event) if(event.phase=="began") then if(tempLine==nil) then tempLine=display.newLine(event.x, event.y, event.x, event.y) tempLine.alpha = 0 -- Random Colors for line r = math.random (0, 255) g = math.random ( 0, 255) b = math.random (0, 255 ) tempLine:setColor(r,g, b) prevX = event.x prevY = event.y end elseif(event.phase=="moved") then tempLine:append(event.x,event.y-2) tempLine.width=tempLine.width+0.9 ractgangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y) ractgangle_hit[i]:setColor(r,g, b) ractgangle_hit[i].width = 4 -- Creates physic joints for line (Turn on draw mode to see the effects) local Width = ractgangle_hit[i].width * 0.5 local Height = ractgangle_hit[i].height * 0.19 -- Physic body for the line shape local lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height} physics.addBody(ractgangle_hit[i], "static", { bounce = -1, density=0, friction=0.7, shape = lineShape}) prevX = event.x prevY = event.y i = i + 1 elseif(event.phase=="ended") then tempLine.parent.remove(tempLine) tempLine=nil if limit > 0 then limit = limit - 1 end end end Runtime:addEventListener("touch", runTouch) |
can I see the full content of level1.lua ?
make sure you have all the below essential parts
1 2 3 4 5 6 7 8 9 10 | module(..., package.seeall) --should have a new() function and it should return a local displaygroup function new() local localGroup = display.newGroup() --add all display objects to localGroup --return localGroup return localGroup end |
Hi,
Thanks for your response. Should that be added to level1.lua ?
Thanks again.
The code on my level1.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 | local ui = require("ui") display.setStatusBar( display.HiddenStatusBar ) soundtrack = audio.loadStream("Maxime game.m4a") --audio.play(soundtrack, {loops = -1}) physics = require ("physics") physics.start() --physics.setDrawMode "hybrid" physics.setGravity(0, 15) stockphoto = display.newImageRect ("stockphoto.png",500,500) stockphoto.x = display.contentWidth/2 stockphoto.y = display.contentHeight/2 topbar = display.newImageRect ("woodtop.png",100,630) topbar.x = display.contentWidth/2.1 topbar.y = display.contentHeight/13.2 topbar.rotation = 90 -- Draw a line limit =160 local scoreTxt = display.newText("100",250,20,native.systemFont,20) local i = 1 local tempLine local rectangle_hit = {} local prevX , prevY local function runTouch(event) if(event.phase=="began") then if(tempLine==nil) then tempLine=display.newLine(event.x, event.y, event.x, event.y) -- Random Colors for line r = math.random (0, 255) g = math.random ( 0, 255) b = math.random (0, 255 ) tempLine:setColor(r,g, b) prevX = event.x prevY = event.y end elseif(event.phase=="moved") then tempLine:append(event.x,event.y-2) tempLine.width=tempLine.width+0.9 rectangle_hit[i] = display.newLine(prevX, prevY, event.x, event.y) rectangle_hit[i]:setColor(r,g, b) rectangle_hit[i].width = 5 tempLine.alpha = 0 -- Creates physic joints for line (Turn on draw mode to see the effects) local Width = rectangle_hit[i].width * 0.6 local Height = rectangle_hit[i].height * 0.2 -- Physic body for the line shape local lineShape = {-Width,-Height,Width,-Height,Width,Height,-Width,Height} physics.addBody(rectangle_hit[i], "static", { bounce = -1, density=0.3, friction=0.7, shape = lineShape}) prevX = event.x prevY = event.y i = i + 1 elseif(event.phase=="ended") then tempLine.parent.remove(tempLine) tempLine=nil end end Runtime:addEventListener("touch", runTouch) local ball = display.newCircle( 0, 0, 12.5) ball:setFillColor(0, 255, 0) ball.x = display.contentWidth/1.1 ball.y = display.contentHeight/4 local function moveHeavens(e) scoreTxt.text = limit if limit < 0 then scoreTxt.text = 0 end end Runtime:addEventListener("enterFrame", moveHeavens ) ring = display.newImage "ringhoop.png" ring.x = display.contentWidth/100 ring.y = display.contentHeight/1.8 ring.alpha = 0.5 --physics.addBody( ring, {friction =0.1, radius = 65,isSensor = true, bounce = 0.1}) --ring.linearDamping = 100 --local function wassup( self, event ) --tempLine = false --end --ring.collision = wassup --ring:addEventListener( "collision", ring) local scaleFactor = 0.20 local physicsData = (require "mybthoop").physicsData(scaleFactor) local hoop= display.newImageRect ("thehoop.png",63,93) hoop.x = display.contentWidth/15.5 hoop.y = display.contentHeight/1.8 physics.addBody( hoop, "static",physicsData:get("hoop") ) hoop.isBodyActive = false point = 0 local function pointPlus(e) if (point == 1) then golda = display.newImageRect ("gold.png",30,30) golda.x = display.contentWidth/25 golda.y = display.contentHeight/10 golda.alpha= 0 transition.to(golda, { time=2000, alpha=1} ) end end Runtime:addEventListener("enterFrame", pointPlus ) local function pointPlus1(e) if (point == 2) then goldc = display.newImageRect ("gold.png",30,30) goldc.x = display.contentWidth/13 goldc.y = display.contentHeight/10 goldc.alpha= 0 transition.to(goldc, { time=2000, alpha=1} ) end end Runtime:addEventListener("enterFrame", pointPlus1 ) local function pointPlus2(e) if (point == 3) then goldb = display.newImageRect ("gold.png",30,30) goldb.x = display.contentWidth/9 goldb.y = display.contentHeight/10 goldb.alpha= 0 transition.to(goldb, { time=2000, alpha=1} ) end end Runtime:addEventListener("enterFrame", pointPlus2 ) gold1 = display.newImageRect ("gold.png",30,30) gold1.x = display.contentWidth/1.4 gold1.y = display.contentHeight/2 physics.addBody(gold1, "static",{radius = 15,isSensor = true}) gold1.isBodyActive = false gold2 = display.newImageRect ("gold.png",30,30) gold2.x = display.contentWidth/3.7 gold2.y = display.contentHeight/2 physics.addBody(gold2, "static",{radius = 15,isSensor = true}) gold2.isBodyActive = false gold3 = display.newImageRect ("gold.png",30,30) gold3.x = display.contentWidth/2 gold3.y = display.contentHeight/2.5 physics.addBody(gold3, "static",{radius = 15,isSensor = true}) gold3.isBodyActive = false local w,h = display.contentWidth, display.contentHeight score = 0 ball.myName = "ball" gold1.myName = "gold1" ball:addEventListener("collision", ball) function ball:collision (event) if event.other.myName == "gold1" and score==0 then transition.to( gold1, { time=400, alpha=0, x=(w/1.4), y=(h/4) } ) point = point + 1 score = score +1 end end score1 = 0 gold2.myName = "gold2" ball.myName = "ball" gold2:addEventListener("collision", gold2) function gold2:collision (event) if event.other.myName == "ball"and score1==0 then transition.to( gold2, { time=400, alpha=0, x=(w/3.6), y=(h/4) } ) point = point +1 score1 = score1 +1 end end score2 = 0 ball.myName = "ball" gold3.myName = "gold3" gold3:addEventListener("collision", gold3) function gold3:collision (event) if event.other.myName == "ball"and score2==0 then transition.to( gold3, { time=400, alpha=0, x=(w/2), y=(h/4) } ) point = point +1 score2 = score2 +1 end end function button2Press(event) drop.isVisible = true Renew.isVisible = false end Renew = ui.newButton{ default = "Renew.png", over = "Renew.png", onPress = button2Press, emboss = true } Renew.x = display.contentWidth/1.1 Renew.y = display.contentHeight/12 Renew.rotation = 0 Renew.isVisible = false ----------------------------------------------------------------------- ----------------------------------------------------------------------- ----------------------------------------------------------------------- ----------------------------------------------------------------------- ----------------------------------------------------------------------- button1Press = function( event ) physics.addBody(ball, {bounce=0.3, radius = 12.5, friction=0.5, density = 200}) drop.isVisible = false Renew.isVisible = true gold1.isBodyActive = true gold2.isBodyActive = true gold3.isBodyActive = true hoop.isBodyActive = true tempLine = false end drop = ui.newButton{ default = "drop.png", over = "drop.png", onPress = button1Press, emboss = true } drop.x = display.contentWidth/1.1 drop.y = display.contentHeight/12 drop.rotation = 0 local button1Press = function( event ) for i = 1, #rectangle_hit, 1 do rectangle_hit[i]:removeSelf() rectangle_hit[i] = nil goldr = display.newImageRect ("gold.png",30,30) goldr.x = display.contentWidth/1.4 goldr.y = display.contentHeight/2 physics.addBody(goldr, "static",{radius = 15,isSensor = true}) goldr.isBodyActive = false goldr2 = display.newImageRect ("gold.png",30,30) goldr2.x = display.contentWidth/3.7 goldr2.y = display.contentHeight/2 physics.addBody(goldr2, "static",{radius = 15,isSensor = true}) goldr2.isBodyActive = false goldr3 = display.newImageRect ("gold.png",30,30) goldr3.x = display.contentWidth/2 goldr3.y = display.contentHeight/2.5 physics.addBody(gold3r, "static",{radius = 15,isSensor = true}) goldr3.isBodyActive = false end end local hi = ui.newButton{ default = "drop.png", over = "drop.png", onPress = button1Press, emboss = true } hi.x = display.contentWidth/14 hi.y = display.contentHeight/12 |
yea you have to do that for Director to load the Screen.