I have an atlas file that contains each of the tiles and I have created a factory to spawn the individual instances of a game object, which contains a sprite to show one of the animations from the atlas.
What I want to do is randomly set the order of the images when I initiate the puzzle. I know I can do this if I list of the animations in an array, shuffle the array and then iterate through each of the items.
However I would like to make this proof of concept more dynamic, so I can reuse the base code with minimal changes if I use a different atlas file. Is there any way of listing out either the frames from an atlas file or the available animations of a sprite?
Wouldnt it be very possible just standardise the names of all the images in the order you want to have them as start? eg. “tile_1.png”, “tile_2.png” “tile_3.png”… etc
Then you could just randomize a “array” of 1,2,3,4 … etc
and then pick the animation as “tile_”…tostring(nr) when randomized.
Every new atlas just need to follow the same naming of the pngs.
It is indeed possible to do as you suggested and is the approach I have had to take. However this requires that either every puzzle contains the same number of tiles or that a small amount of configuration is required for each puzzle, for example the number of tiles and the size of each tile.
If I was able to programmatically access the images from the atlas file then I could have coded my application to scan the chosen atlas file, store the names, use the image count to work out the grid size and the tile size.