How to load and unload resources in GameMaker 8.0

Greetings people!
I wanted to know if there is any way to avoid the default option of GameMaker in which all the game assets are always loaded at startup.
This causes performance problems, usually leading to the classic "An error has occured" or sometimes even "Lack of memory".
Sadly, I have GameMaker 8.0, which does not have an option or "drag and drop" feature that gives such option (or at least I didn't found it).
I checked if there was any kind of option in the Global Game Settings, but nothing.

What I need, is some kind of code, script or whatever, that can manually load and unload the game's resources (mainly sprites).
Better if it can be made in drag and drop, but if it's via script then I would like an explanation on how it works.
So, if there is a way to do so, let me know!

Thank you so much guys! I hope that I made myself clear (I'm dumb in these things).
 

Binsk

Member
I believe with GameMaker 8 your only option is to manually load them through code. You will no longer have the convenience of editing sprite origins, masks, etc. in a visual editor, however.

I don't have a version of the GM8 manual available at the moment but you should have the functions such as sprite_add, sound_add, etc. (It might be _load or _create, I can't remember). Check the manual for more details.

Effectively what you will want to do is add the sprites, sounds, etc. you want to load LATER in the game to your included files rather than importing them into GameMaker. When the game is running you call the appropriate function and specify the local file path. It will load it into the game and the function returns an ID that you can store in a variable.

You then use this variable in place of a sprite / sound / etc. name.

Make sure you only load in each resource once. This, or make sure to delete it before you load it in more than once otherwise you will have a memory leak.

Unlike an actual resource name, variables can be overwritten and, if they are containing an id of a resource, the resource won't be freed and you will lose the ability to free it. Thus why you should only load it once or make absolutely sure to delete it if you plan on loading it again later.
 
I believe with GameMaker 8 your only option is to manually load them through code. You will no longer have the convenience of editing sprite origins, masks, etc. in a visual editor, however.

I don't have a version of the GM8 manual available at the moment but you should have the functions such as sprite_add, sound_add, etc. (It might be _load or _create, I can't remember). Check the manual for more details.

Effectively what you will want to do is add the sprites, sounds, etc. you want to load LATER in the game to your included files rather than importing them into GameMaker. When the game is running you call the appropriate function and specify the local file path. It will load it into the game and the function returns an ID that you can store in a variable.

You then use this variable in place of a sprite / sound / etc. name.

Make sure you only load in each resource once. This, or make sure to delete it before you load it in more than once otherwise you will have a memory leak.

Unlike an actual resource name, variables can be overwritten and, if they are containing an id of a resource, the resource won't be freed and you will lose the ability to free it. Thus why you should only load it once or make absolutely sure to delete it if you plan on loading it again later.
Thank you, but I find hard the use of it.
A big amount of my sprites mainly focus on sprite origins...
But I appreciate the help anyway. I could still use it for sounds.

Thanks man!
 

TsukaYuriko

šŸŒ 
Forum Staff
Moderator
Focus on whatever uses the most resources. That's usually background music, sounds and large backgrounds, in that order. As soon as you have that additional headroom, the memory used by the leftover massive batch of smaller resources becomes less of an issue and, therefore, externalizing them becomes less of a necessity.
 
Focus on whatever uses the most resources. That's usually background music, sounds and large backgrounds, in that order. As soon as you have that additional headroom, the memory used by the leftover massive batch of smaller resources becomes less of an issue and, therefore, externalizing them becomes less of a necessity.
My sprite sheets are usually 3000x4000.
I guess backgrounds and sounds are probably the least of my problems.
 

FrostyCat

Member
The Manual for legacy GM 8 said:
sprite_add_sprite(fname) Adds the sprite stored the file fname to the set of sprite resources. The file must be a .gmspr file that is saved in the sprite property form in GameMaker. As this file contains all sprite settings, no further arguments are required. The function returns the index of the new sprite that you can then use to draw it or to assign it to the variable sprite_index of an instance. When an error occurs -1 is returned.
 

TheouAegis

Member
Did GM8 allow 3000x4000? It's been so long, but I could have sworn we established GM8 was on the low end of texture pages with a limit of 2048.
 
Top