so when i add this piece of code into the scene create it works perfect but when i put it into the scene show it lags and crashes corona…
local i = 5 local circle = {} local spawnCircles = function () local FallDown = math.random(display.contentWidth \* 0.2, display.contentWidth \* 0.8 ) circle[i] = display.newImageRect("circle.png", 31, 31 ) circle[i].x = FallDown circle[i].y = -70 physics.addBody( circle[i], "dynamic", {density = .01, friction = 0.5, bounce = 0.1 }) circle[i].gravityScale = 0.1 physics.setGravity( 0, 10 ) circle[i]:addEventListener( "collision", circle) i = i + 1 if i == 10 then -- i = 10 means 10 circles will be created in the circleTable i = 5 end end myTimer = timer.performWithDelay( 2000, spawnCircles, -1) --1000 is the time
this is the game.lua code…
local composer = require( "composer" ) local scene = composer.newScene() local \_W = display.contentWidth local \_H = display.contentHeight local physics = require("physics" ) physics.setScale( 30 ) physics.setGravity( 0, 0 ) physics.start( ) physics.setDrawMode( "hybrid" ) function scene:create( event ) local sceneGroup = self.view physics.start() ---------------------------- local BackGround = display.newImageRect("BackGround.png", 1080, 1920) return true end ---------------------------- ---------------------------- function scene:show( event ) local sceneGroup = self.view physics.start() ----------------------------- ----------------------------- local i = 5 local circle = {} local spawnCircles = function () local FallDown = math.random(display.contentWidth \* 0.2, display.contentWidth \* 0.8 ) circle[i] = display.newImageRect("circle.png", 31, 31 ) circle[i].x = FallDown circle[i].y = -70 physics.addBody( circle[i], "dynamic", {density = .01, friction = 0.5, bounce = 0.1 }) circle[i].gravityScale = 0.1 physics.setGravity( 0, 10 ) circle[i]:addEventListener( "collision", circle) i = i + 1 if i == 10 then -- i = 10 means 10 circles will be created in the circleTable i = 5 end end myTimer = timer.performWithDelay( 2000, spawnCircles, -1) --1000 is the time --------------- return scene end -- this end ends the scene:show -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene
this game.lua crashes corona … can you tell me what im doing wrong? thanks