Coming from Blitz, I got very used to not having to remember long strings of numbers as to where I had loaded a particular sprite or sound effect, as they were assigned handles instead. As an example, we may have had something like:-
Global piano
piano=LoadImage("piano.png")
DrawImage piano,0,0
Obviously, adding this as it stands would mean massive rewrites of code, and upsetting people who are used to the current method, so could I suggest a compromise? What about adding a HANDLE command? Perhaps GL could then just allocate numbers to all the handles and substitute at compile time? This may end something like this:-
HANDLE piano
LOADSPRITE "piano.png",piano
DRAWSPRITE piano,0,0
Any thoughts?
German but useful ;)
You can help me a little bit :P
http://www.glbasic.com/forum/viewtopic.php?id=1376
That's cool Schranz0r, but the addition of a HANDLE command would mean not having to worry about an extra type, and could be used for animated strips, sounds, streams, and probably other things too, giving a lot more flexibility
hmm
The thing is, I am not trying to turn GL into Blitz (or I may as well just carry on using Blitz!) but rather looking at the best features of Blitz and suggesting incorporating them into GL
I use something similar to the above :-
GLOBAL IMG_MOUSE_POINTER$ = "mouse-pointer.png"
GLOBAL IMG_MOUSE_POINTER_HANDLE = 0
GLOBAL IMG_MOUSE_POINTER_SHADOW$ = "mouse-pointer-shadow.png"
GLOBAL IMG_MOUSE_POINTER_SHADOW_HANDLE = 5
GLOBAL IMG_SPLASH$ = "splash.png"
GLOBAL IMG_SPLASH_HANDLE = 10
GLOBAL image_dir$ = "./data/images/"
...
...
FUNCTION load_media:
LOADSPRITE image_dir$ + IMG_MOUSE_POINTER$, IMG_MOUSE_POINTER_HANDLE
LOADSPRITE image_dir$ + IMG_MOUSE_POINTER_SHADOW$, IMG_MOUSE_POINTER_SHADOW_HANDLE
LOADSPRITE image_dir$ + IMG_SPLASH$, IMG_SPLASH_HANDLE
ENDFUNCTION
I'm using global variables as constants/defines. That's why I made them uppercase.
Which is fine, but declaring global variables all over the place uses up memory - not a big problem on the average desktop machine, but much more critical on portables
Hey Peejay
I know where you're coming from, I guess it's more an object way of thinking. I also guess it may require some sizeable changes to the way GLB works.
In the mean time, have you tried Schranz0r's useful code snippet.
Would allow you to do this:
GLOBAL myPlayer = LoadImage("Player.png")
LoadImage goes off to crawl the list of sprites created to find an empty one, then it loads it into it and returns the sprite Id. You store that in myPlayer var for example, which is not a million miles away from how BMax and other object orientated languages would do it, only you have an Id to a sprite rather than a pointer to an object in memory.
I've expanding this idea for my use, I was adding in support for LoadAnim too, which is what sparked those posts about needing the ZOOM and ROTATE commands for ANIM's. I've created functions for SETROTATION, SETSCALE and SETALPHA and also SETHANDLE, MIDHANDLEIMAGE and other handy functions. Just now I'm stuck with ANIM's not yet having the functionality I need for rotate and scale, so it's either wait for them or use POLYVECTOR or (shudder) GRABSPRITE to put everything into it's own sprite and use a manager (like LOADIMAGE above) to also handle my own ANIM 'objects' and never go near Sprite Id's directly.
You could very simply wrap LOADSPRITE :-
GLOBAL IMAGE_HANDLE_CAT = MYLOADSPRITE("image_cat.png")
GLOBAL IMAGE_HANDLE_DOG = MYLOADSPRITE("image_dog.png")
FUNCTION MYLOADSPRITE: filename$
STATIC image_handle
INC image_handle, 1
LOADSPRITE filename$, image_handle
RETURN image_handle
ENDFUNCTION
...which is what Schranz0r's doing without types.
[EDIT]
Actually this is so much more efficient than what I was doing above I'm implementing it too :)
Yepp STATIC, you can do that with all Mediafiles..
Nice!