Level Building Problem

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?

Please use < lua > tags when you post code to make it a little more legible ;)

What errors are you actually getting?

Have you tried moving the event.phase to ended rather than began in your collision function?

Peach :)

Sorry about the illegible code, was sorta in a rush when I post it, also first time posting code problems on here.

The thing is, I am not getting any errors, at least not errors in the output. Instead the loop is just stopping when it reaches a tile with a physics body attached to it when it goes through them in the next level.

Also I did try moving it to event.phase == "ended" and that did not change it.

Hey again,

No worries about the code - it just makes it more likely you'll get people responding so a good habit to get into.

If you produce some plug and play code someone may be able to run this for you and assist.

Peach :)

views:1427 update:2011/12/30 9:10:41
corona forums © 2003-2011