02-17-2023, 01:17 AM
(02-17-2023, 12:34 AM)PhilOfPerth Wrote: I have a folder containing several images (.jpg) that I want to place in an array, then pick any (or all) from that array to display. I don't see any appropriate commands that allow this; are there any? (simplicity is important to me!)
I do this all the time in my games. I use an array of LONG INTEGERS to preload images then call upon each array index when I need the images.
DIM Image(10) AS LONG
Image(0) = _LOADIMAGE("image001.jpg", 32)
Image(1) = _LOADIMAGE("image002.jpg", 32)
Image(2) = _LOADIMAGE("image003.jpg", 32)
Image(3) = _LOADIMAGE("image004.jpg", 32)
Image(4) = _LOADIMAGE("image005.jpg", 32)
etc..
etc..
You can assign descriptive variable names if you like as well:
WaterFall& = Image(0)
Forest& = Image(1)
SunSet& = Image(2)
etc..
_PUTIMAGE (0, 0), SunSet&
or
_PUTIMAGE (0, 0), Image(2)
Don't forget to free the images before your program terminates:
FOR i = 0 TO 10
_FREEIMAGE Image(i)
NEXT i
Look at the code for any of my games and you'll see I use this method quite extensively.