Loading images to be called by the data of a value

BlitzPlus Forums/BlitzPlus Beginners Area/Loading images to be called by the data of a value

Yeah you're not going to want a game that creates 360 bmp images in a directory, that's not good and users will not like you cluttering up their hard drive. Plus, if you want to rotate more than one image, you're going to be cluttering up the works greatly. Also, you'd have to have about 720 LoadImage lines for three rotated images. Works, but not efficient. I think this is what you need:

Graphics 800,600,32,2
Text 0,0,"LOADING, PLEASE WAIT"
Flip

;create a red block
redblock=CreateImage(64,64,1)
SetBuffer ImageBuffer(redblock)
Color 255,0,0
Rect 0,0,63,63,1

;and a blue block
blublock=CreateImage(64,64,1)
SetBuffer ImageBuffer(blublock)
Color 0,0,255
Rect 0,0,63,63,1

;and a green
greblock=CreateImage(64,64,1)
SetBuffer ImageBuffer(greblock)
Color 0,255,0
Rect 0,0,63,63,1

;make a multi dimentional array... has 360 rows, and 3 colums (one for each block)
Dim rotatedimages(360,3)

For x=0 To 359 
	tmpimg=CopyImage(redblock) ;copy the red block
	RotateImage(tmpimg,x)  ;rotate it x degrees
	rotatedimages(x,0)=tmpimg  ;put it in the x row of the first column (0),
Next

;do the same for the other two images
For x=0 To 359
	tmpimg=CopyImage(blublock)
	RotateImage(tmpimg,x)
	rotatedimages(x,1)=tmpimg
Next
For x=0 To 359
	tmpimg=CopyImage(greblock)
	RotateImage(tmpimg,x)
	rotatedimages(x,2)=tmpimg
Next


SetBuffer BackBuffer()
angle=0

While Not KeyHit(1)
	Cls
	DrawImage rotatedimages(angle,0),100,100  ;select the image row and column (angle and 0(red)) and draw
	DrawImage rotatedimages(Rnd(0,359),1),100,200 ;put in a random angle for a random row in the array, 1 for blue
	DrawImage rotatedimages(54,2),100,300  ;or just pick an angle and 2 for green
	angle=angle+1 ;add angle to keep it rotating
	If angle>359
		angle=0
	EndIf
	Flip
Wend 

;----------------------
;Here's how you could put it into function form, just make sure you don't pick an index that's more columns that
;the array you initialized :)

;Function RotateImagetoArray(image,index)
;For x=0 To 359
;	tmpimg=CopyImage(image)
;	RotateImage(tmpimg,x)
;	rotatedimages(x,index)=tmpimg
;Next


I used arrays, and at the bottom wrote an example of how you could do it in function form. If you wanted to quicken the loading time, try rotating in increments of 2 instead of one. You're rotations will be every two degrees, but you might benefit more from the shorter load time.
I hope this helps :)