Hi,
I am struggling here, I have 2 modules, player.lus, obsticle.lua.
I have gems created in the obsticle.lua and the player alond with the collision function in the player.lua.
The collisions are working fine but I am unable to remove the gem cleanly.
If I use event.other:removeSelf() it will remove the gem but I get an error in the function I use to move them.
I know I have to remove the gem from the table but I just cant it to work…
The player module dosnt see the gem table and if I pu the removal function in the obsticle.lua where i create them i cant pass event other.
any advcie would be cool:
[lua]
-----------------obsticles.lua----------------
function createObsticles()
gems = {}
gems[1] = display.newImage(layer,“images/gem1.png”)
gems[1].x = 50; gems[1].y = display.contentHeight /2 -30
gems[1].dx = speed
physics.addBody(gems[1],“static”)
gems[1].type = “gems”
…gems[2], gems[3] ,etc etc, etc …
local tPrevious = system.getTimer()
local function move2(event)
local tDelta = event.time - tPrevious
tPrevious = event.time
local g
for g = 1, #gems, 1 do
gems[g].x = gems[g].x - gems[g].dx * tDelta * 0.2
if (gems[g].x + gems[g].contentWidth) < 0 then
gems[g]:translate( 1080 + gems[g].contentWidth * 2, 0 )
end
end
end
Runtime:addEventListener( “enterFrame”, move2 )
end
------------------------------------player.lua------------------------------
local player
function createPlayer()
player= display…blah blah blah
function player:collision(event)
local phase = event.phase
if event.phase == “began” then
event.target.type == “player” and event.other.type == “gems” then
print("…gem collision")
end
end
end
[/lua]