Danny, I’m trying to use the above steps to identify collisions with a randomly generated level. I’ve tested this with normal images that are in a static level, but random barriers are really giving me trouble. Here is my level code:
local function buildGrid()
-- build map array --
for x = 0, kLevelCols do
level[x] = {}
for y = 0, kLevelRows do
local probability = math.random(0,10)
if probability \<= kRoadProbability then
level[x][y] = 1
cell2 = display.newImage(cellTable2, x\*cellWidth, y\*cellHeight)
background:insert( cell2 )
else
level[x][y] = 2
cell1 = display.newImage(cellTable1, x\*cellWidth, y\*cellHeight)
barrier:insert( cell1 )
end
end
end
end
buildGrid()
--[[
-- build screen now --
for x = 0, kLevelCols do
for y = 0, kLevelRows do
if level[x][y] == 2 then
cell1 = display.newImage(cellTable1, x\*cellWidth, y\*cellHeight)
barrier:insert( cell1 )
elseif level[x][y] == 1 then
cell2 = display.newImage(cellTable2, x\*cellWidth, y\*cellHeight)
background:insert( cell2 )
end
end
end
]]
I commented out the bottom portion of the level generation code as I can populate the level without it, but collisions aren’t detected regardless of which portion is called. Below is my very very simple collision detection code:
local function drag(event)
if event.phase == "moved" then
hero.x = event.x
hero.y = event.y
print (hitTestObjects(hero, img2))
end
end
hero:addEventListener("touch", drag)
I know that the barrier cells are being generated uniquely as when I run the code with debug physics enabled, I can see the boundaries clearly. The main problem here is that run my code, collisions sound as soon as the player enters the grid, whether it is touching a barrier or the background. I tried removing the background cell from the barrier group, but that didn’t work at all. I’m kind of at a roadblock. Any suggestions, or am I just creating the level in a poor way? Let me know if I can provide any additional info. Thanks for your time!
[import]uid: 135394 topic_id: 22404 reply_id: 107579[/import]