Quote: "You could do something like CopyImage and loop through spritesheet."
That is what I was thinking too, only I would save using the array for the layout of the map.
Just make a set of sprites from the sprite sheet then make a little map editor to clone the sprites for the array for the map grid.
Quote: "his " 16 tiles in a row and 12 rows of image data on a 512 by 384 pixels", what do you mean? 16 columns and 12 rows?"
Yes, from his dimensions given, they are 32 x 32 pixels for each image.
My code is like yours but a bit different for the example... (image is attached to run this code if you want)
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "testing" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetClearColor(155,155,155)
LoadImage(666666, "tile_set_ce.png")
print("Loading the sprites. Please wait....")
sync()
for c = 1 to 12
for e = 1 to 16
temp_counter = temp_counter + 1
CopyImage(temp_counter,666666,x,y,32,32)
CreateSprite(temp_counter, temp_counter)
SetSpriteSize(temp_counter, 64,64)
SetSpritePosition(temp_counter, -100,0)
x = x + 32
next e
x = 0
y = y + 32
next c
temp_counter = 1
SetSpritePosition(temp_counter, 200,100)
do
if GetRawKeyReleased(38)
SetSpritePosition(temp_counter, -100,0)
temp_counter = temp_counter + 1
if temp_counter > 192 then temp_counter = 1
SetSpritePosition(temp_counter, 200,100)
endif
if GetRawKeyReleased(40)
SetSpritePosition(temp_counter, -100,0)
temp_counter = temp_counter - 1
if temp_counter < 1 then temp_counter = 192
SetSpritePosition(temp_counter, 200,100)
endif
print("")
print("")
print("")
print(" " + str(temp_counter) )
print("")
Sync()
loop
I am using a temporary counter to go from 1 to 192 for the images, and each sprite being created is using an image assigned with the same number.
You can use the up and down arrow keys to cycle through the tiles. (notice that I resized the sprites to 64 x 64 to make them easier to see)
You can see the nested loop is like his, 16 inside of 12, because we increment the x position in the inner loop for each column.
Then, the outer loop is dropping down a row by an increment to the y position for the copied image.
Notice you have to reset the x position back to 0 each time you start the outer loop so we start our new row back at the starting position.
Like I said, I would save the array for the actual layout of the map for a logical order for the sprites made from the sprite sheet that are being cloned for the array.
That way, the array would be set up logically for the grid of the map and not the sprite sheet, but it can be set up multiple ways so it doesn't really matter.
That is just one way of doing it, and it would really depend on the map editor being used as to how you want to load these images and build your array.
As PartTimeCoder says, there should be some great tools for map making already in the forums that you will find by searching.
If you replace my image with yours, then you will cycle through your tiles with the sprite number being shown for each one.
I thought that numbering an image for you would help you understand how we are copying these images.
Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1