Here’s my problem. I create a bunch of enemies and add them to physics then to a display group called enemyGroup. I move enemmGroup.x + 40 pixels. Now the collision listener is in the same location even though the enemies have moved.
Has anyone encountered this before? Try this code to see what I mean
[lua]local group1 = display.newGroup()
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 9)
local box = display.newRect(50,50,30,30)
physics.addBody(box, “static”)
box.name = “box”
group1:insert(box)
group1.x = group1.x+100
local function fire( event )
local bullet = display.newCircle(event.x,event.y,5)
physics.addBody(bullet, “dynamic”)
bullet.gravityScale = -1
bullet.name = “bullet”
end
local function onCollision ( event )
if event.object1.name == “box” or event.object2.name == “box” then
print("hit at: "…event.object1.x)
end
end
Runtime:addEventListener(“collision”, onCollision)
Runtime:addEventListener(“touch”, fire)
[/lua]
Click under the box, then click to where the box used to be.
I believe the solution is to do a for loop for each item in enemyGroup and move them, but that uses more processing power?