Hello. I’m making a literal jigsaw game, for PC, my first project after numerous tutorials.
I have made the main menu. I now need the next screen after “New Game” to be a dynamic photo grid, where you select the image you want (images loaded from a res sub-folder).
I have found one tutorial where it shows this part, but it is for a mobile application and i’m not sure if one particular part is relevant. This is the video in question. The creator in question seems to have abandoned this channel so I can’t ask them. I am at a part where they are referencing a node that refers to the mobile OS user itnerface (roughly the 06:34 mark, it is also refernced nearer the start of the video). This makes it look like, to me, the code might only be relevant when used on mobile, which I am not. I have searched for another tutorial on how to make a photo grid and nobody seems to have made one.
Please may you give me some pointers?
So at the moment, you just want to display the results of the image directory search, is that right?
Off hand, it seems like your best bet would be to construct something dynamically at runtime that fits the number of pictures you need to show:
- Using Controls: building an auto-sized and auto-centered grid out of a variable number of HBoxContainers and VBoxContainers (do this if, for example, you want 7 pictures to show up as centered rows of uneven length instead of a partially-filled square grid), or use a GridContainer of dimensions determined at runtime (found 23 pictures? Most likely you want a 5x5 grid then, but that depends on the aspect ratio of the pictures). Also explore ScrollContainer if you end up with more pictures than can be displayed at once.
- Using Sprite2Ds: instantiating a bunch of sprites and arranging them on the screen with calculated offsets, based on how many need to be displayed. This would essentially emulate the first option with kinematic arrangement instead of letting the engine do the heavy lifting for you, but you might prefer this approach if Controls feel tricky to you.
In general, you will have more success finding tutorials for things if you are able to abstract something more general from your specific use-case (“how to use GridContainer” vs “how to make a photo grid”), but that’s easier said than done when you aren’t sure where to start. The only reason I mention it is, if you aren’t finding the tutorial you need, you probably just aren’t asking the best questions you could be! What I mean is, it’s nothing to be discouraged over; it just takes some more digging and a reframing of sorts.