Thanks for the reply. I haven’t checked the memory usage. Seemed to work fine, of course I only ran this in the simulator so far. Is there a more efficient approach that I’m missing?
I’d really like to make this scroll. I’m trying to this together in my head. My plan at this point is to add all sprites to a group. move the whole group up. When the sprites in the top row get above the top of the stage move them below the bottom row and change the frame number to new frames showing the new tile images.
I’m also picturing adding a second layer or third layer of sprites to show back ground elements and foreground elements over laying the main scenery.
Here’s the code I have so far, slightly updated from the code above. Here I added an array describing the tiles that make up the map I want to display.
[lua]display.setStatusBar( display.HiddenStatusBar ) – hide the status bar
– Include sprite module
require “sprite”
local tile_size = 32 – set the tile size to 32
local tile_group = display.newGroup()
tile_group.x = tile_size / 2 – offset the group half the width of a tile so the tiles align with the upper left corner of the screen
tile_group.y = tile_size / 2
– name the image file containing your sprites, followed by the width and height of each sprite
local back_sheet = sprite.newSpriteSheet(“Scenery.png”, tile_size, tile_size )
– Define an array that describes the tiles used to create the scene.
local tile_array = {20,10,10,10,10,10,10,18,16,18,
20,19,19,19,19,19,19,17,17,20,
23,19,19,19,19,19,19,19,19,20,
20,19,1,1,1,1,1,1,1,20,
20,19,1,32,33,36,34,32,1,20,
20,18,1,24,33,35,34,24,1,20,
23,15,17,31,33,35,34,31,15,20,
27,26,26,26,26,26,26,26,26,28,
29,14,10,13,14,13,13,14,10,30,
29,13,12,9,13,13,12,11,10,30,
29,11,10,10,11,12,13,14,9,30,
26,26,26,26,26,26,26,26,26,26,
14,14,14,14,14,14,14,14,14,14,
21,21,21,21,21,21,21,21,21,21,
22,22,22,22,22,22,22,22,22,22}
– Create a set by naming the sheet and starting frame and number of frames
local back_set = sprite.newSpriteSet( back_sheet, 1, 36)
local count = 1 – use this to count the tiles created
for col = 1, 15, 1 do
for row = 1, 10, 1 do
sprite.add( back_set, “tile”…count, 1, 1, 1000, -1 )
local tile_sprite = sprite.newSprite( back_set )
tile_sprite.currentFrame = tile_array[count]
tile_sprite.x = ( (row-1)*tile_size )
tile_sprite.y = ( (col-1)*tile_size )
tile_group:insert( tile_sprite ) – add tile sprite to tile group
count = count + 1
end
end[/lua] [import]uid: 98652 topic_id: 19670 reply_id: 76138[/import]