I am currently working on a multiple level physics game, where I am using the Director Slim class and also building my levels using Tables and loops. My levels have been building fine before, but I've been testing transitions using a mouse click. Now that I have a collision with the end goal activating the transition it breaks how my level builds.
This is my code that builds out the level
local tile = {}
for i = 1, #map do
local row = map[i]
for j = 1, #row do
local tileNum = row[j]
tile[tileNum] = display.newImage(tiles[tileNum])
tile[tileNum].x = (tile[tileNum].width * (j-1)) + tile[tileNum].width/2
tile[tileNum].y = (tile[tileNum].height * (i-1)) + tile[tileNum].height/2
tile[tileNum].asset = tiles[tileNum]
levelGroup:insert(tile[tileNum])
if tile[tileNum].asset == "platformpiece.gif" then
physics.addBody(tile[tileNum], "static", {friction = 0.5, bounce = 0.3})
end
--if tile[tileNum].asset == "platformend.gif" then
--physics.addBody(tile[tileNum], "static", {friction = 0.5, bounce = 0.3})
end
if tile[tileNum].asset == "platformend2.gif" then
physics.addBody(tile[tileNum], "static", {friction = 0.5, bounce = 0.3})
end
if tile[tileNum].asset == "endclosed.gif" then
physics.addBody(tile[tileNum], "static", {isSensor = true})
end
end
end
And this is the code that activates the level transition when the Player Circle hits the end goal
ircle.collision = function (self, event)
if(event.phase == "began") then
print("Collisions Man")
if(event.other.class == "collectible") then
event.other:removeSelf()
score = score + 1
updateScore()
if (score == 3) then
tile[6].class = "end"
end
end
if(event.other.class == "end") then
director:changeScene("level2")
end
end
end
circle:addEventListener("collision", circle)
When I used a touch transition the next level built fine, but ever since I switched it to this, the level starts to build until it hits a tile that has a physics body and then it just stops going through the loop.
I'm panicking since I need this done soon, and no one I know uses Corona. Any suggestions?