I have a small 32x32 tile I would like to use as an endlessly scrolling background. It’s a seamless tile for grass, and I want it to look like the ground is constantly moving (the player is running).
This is my current solution.
First, in my initialization function:
[lua]local id = 0
for row = 0, display.contentHeight+128, 32 do
for col = 0, display.contentWidth, 32 do
background[id] = display.newImage(“tile-grass.png”)
background[id].x = col
background[id].y = row
id = id + 1
end
end
backgroundTilesTotal = id[/lua]
then, in my game loop:
[lua]for id = 0, backgroundTilesTotal, 1 do
local newY = background[id].y + cameraY
if newY > display.contentHeight + 64 then
newY = newY - display.contentHeight - 128
end
background[id].y = newY
end[/lua]
This basically keeps shifting all of the tiles down (cameraY is basically the speed), which makes it look like the background is moving.
I have a feeling this is eating up a decent amount of performance, and there are also occasional “seams” that show up between the tiles.
I tried searching the forums, and google for alternate solutions, but came up short. Anyone have a better solution, or a suggestion on how to do this differently? Would using larger tiles (say, 128x128 instead of 32x32) be better for performance? [import]uid: 49447 topic_id: 15896 reply_id: 315896[/import]