[UPDATE: I solved it by completely redo’ing the code.]
Hi Everyone,
I’ve got an array which holds tiles.
And on certain tiles I add a physics Body to them, this means on tiles numbered , say, 01, I get a 40x40 physics body. (A tile size.)
However when I drag the screen the physics bodies don’t stay with the image it was made for.
Rather they move as well but once 1 tile out of their original position they snap back to their old position again.
This is likely something to do with the group they’re in.
I’ll post a small bit of code to try to help:
local map = display.newGroup()
...
for y = 0, map.yTiles - 1 do
for x = 0, map.xTiles - 1 do
--Read my Array (sceneryTiles) and places down the correct tiles.
map.sceneryTiles[#map.sceneryTiles +1] = map.sceneryTiles[1][(1+y)][(1+x)]+ 1
--Add a static Physics Body to certain tiles.
if map.sceneryTiles[1][(1+y)][(1+x)]+ 1 \< 4 and map.sceneryTiles[1][(1+y)][(1+x)]+ 1 \> 1 then'
physics.addBody(map[#map.sceneryTiles-1],"static") -- \<= Expected problem area.
print(#map.sceneryTiles) -- Correctly reads tile number in the above range.
end
end
end
As you can see I add the physics body to the ‘map’ which is a Group I created for all the tiles to go in.
I believe that’s why it’s messing up, the tiles are always on screen and that’s why they’re snapping back into position even though the images are not.
Any idea how I add the bodies to the images, Efficiently?
Any help would be appreciated.
Matt [import]uid: 91798 topic_id: 29441 reply_id: 329441[/import]