Hi Friends!!!, well I have always this doubt.. never rebember how I did it...
Well I want load a battery of .png in example, but using GENSPRITE()
I want make somthing like this... but always have troubles into the code... appears Sprites not correpond... waht I need...
global spr_Offset = gensprite()
For n_Item=0 to 100
loadsprite "spr_Bkg"+n_Item+".jpg" , n_Item + spr_Offset
next
//This don´t works, and I´m sure I make works somthing similar to this... but I don´t rebemer it...
Thanks in advance for your Help....
Iván J
Your code *should* work, except you run the chance of overwriting an existing sprite id.
It would be ok if the entire 100 incremental sprites ids are available, but no checks are done.
And making sure you realize your code expects '101' sprites (0 to 100 is 101 sprites).
If you are just trying to load 100 sprites with the same name + index, then I'd use a TYPE again, such as:
TYPE TSprite
id% // Sprite id, used by GLBasic sprite commands
FUNCTION Load: path$
IF DOESFILEEXIST(path$)
self.id = GENSPRITE()
LOADSPRITE path$, self.id
ELSE
self.id = -1
DEBUG "** File NOT FOUND!: [" + path$ + "]\n"
ENDIF
ENDFUNCTION
ENDTYPE
Then the code that handles your situation:
GLOBAL sp_backgrounds[] AS TSprite
DIM sp_backgrounds[100] // Array 0 to 99
FOR n_item = 0 TO LEN(sp_backgrounds[]) - 1
sp_backgrounds[n_item].Load("spr_Bkg" + n_item + ".jpg")
NEXT
This will automatically give each of the 100 (not 101 in this code) sprites a unique and available sprite id.
Then to draw the sprites, use this:
DRAWSPRITE sp_background[49].id, 100, 100
Thanks Master!!!, =D =D
You´re a crack, like Mesi :nw: :nw: