Hi. My problem is quite big, i need someone to help me.
About the game :
It has two levels: game.lua and game2.lua. If the player earns 10 points, s/he should go to the next level using composer.gotoScene(“game2”, “slideLeft”). Level 1 works fine, level 2 is a slightly modified version of the 1st one (on its own, it works fine too).
The problem : when the player is about to go to the next level, i see an error message. Somehow i need to make the transition work.
Error 1 : game2.lua: 281 : physics.addBody() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event
Line 281 : physics.addBody(player, “static”, physicsData:get(“shipPlay”))
It is a part of:
player = display.newImage(sceneGroup, "images/shipPlay.png") player.x = L + 70 player.y = CY player.name = "player" physics.addBody(player, "static", physicsData:get("shipPlay"))
Error 2 : game2.lua: 288 : physics.addBody() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event
Line 288 : physics.addBody(playerWall, “static”)
It is a part of: (playerWall helps with collision detection, to earn points)
playerWall = display.newRect(sceneGroup, 0, 0, 50, CH) playerWall.x = L - 60 playerWall.y = CY playerWall.name = "playerWall" physics.addBody(playerWall, "static") playerWall.alpha = 0
Error 3: game.lua:75: bad argument #-1 to ‘newImage’ (Proxy expected, got nil)
Line 75 :
obstacles[obstaclesCounter] = display.newImage(sceneGroup, "images/"..name..".png" )
It is a part of: (The function is above onCollision function)
local function sendObstacles() local names = {"obstacle1", "obstacle2", "obstacle3"} local name = names[math.random(#names)] obstacles[obstaclesCounter] = display.newImage(sceneGroup, "images/"..name..".png" ) obstacles[obstaclesCounter].x = R + obstacles[obstaclesCounter].width obstacles[obstaclesCounter].y = math.random(T+40, B-40) obstacles[obstaclesCounter].name = "obstacles" physics.addBody(obstacles[obstaclesCounter], physicsData:get(name)) obstacles[obstaclesCounter].isFixedRotation=true transition.to(obstacles[obstaclesCounter], {x=L-40, time=obstaclesTravelSpeed}) obstaclesCounter = obstaclesCounter + 1 end