Code question for someone...

Blitz3D Forums/Blitz3D Beginners Area/Code question for someone...

Galdy(Posted 2011) [#1]
I was wondering if there is an efficient (or possible) way to pass the handle of twenty different images I
have through the code below via a loop? They are numbers I made in paint shop pro 7 numbering one
through twenty, i.e., one, two,three, four.....etc. I’m just trying to approximately center the handles.

Here’s the code. snippet

  
  x#=ImageWidth (One)/2 
   y#=ImageHeight (One)/2 
   x=Ceil#(x) 
   x=Ceil#(y) 
  HandleImage One,x,y 
 
;Again for image 'two'  if i can’t do it  in a loop 
   x#=ImageWidth (two)/2 
   x#=ImageHeight (two)/2 
   x=Ceil#(x) 
   x=Ceil#(y) 
   HandleImage two,x,y 


I can’t seem to substitute another variable in place of the image handle so I can just make a loop of it.
Leading me to believe i’ll have to make twenty of these snippets of code for all twenty Images.

Last edited 2011


Yasha(Posted 2011) [#2]
Unless I've totally misunderstood what you want to do, this is what arrays are for.

1) Name your files with a number: "MyImage_1.png" or something.

2) To load the files:
Local img[20], i
For i = 1 to 20
    img[i] = LoadImage("MyImage_" + Str(i) + ".png")
Next


3) To centre the images:
For i = 1 to 20
    x#= Ceil(ImageWidth(img[i]) / 2.0 )
    y#= Ceil(ImageHeight(img[i]) / 2.0 )
   HandleImage img[i],x,y 
Next


Unlike other variables, arrays have to be declared with an explicit Local, Global or Field (or Dim, if using the other kind of arrays that Matty demonstrates below).

Last edited 2011


Matty(Posted 2011) [#3]
graphics 512,512,0,2

Dim ImageList(20)

For i=1 to 20
	;load images in this case assumed to follow
	;a naming pattern of "MyImage1.bmp" "MyImage2.bmp" etc 
	ImageList(i)=loadimage("MyImage"+Str(i)+".bmp")
	if Imagelist(i)<>0 then midhandle ImageList(i)
next





Galdy(Posted 2011) [#4]
I see. Cool. Problem solved. Thanks