GameMaker A few questions

U

User

Guest
Hi!

1) When i developing the game, i use some images, objects, instances. The volume of my graphics (images) will be about 100-200 megabytes. So i need to load it in my game.
I created objects and place objects in my room. Now i need to load sprites.

I see two ways.

First - load all sprites to all objects at the begining of my game. All at once.
Create loading_room with a progress bar, load graphics and change progress bar value.
Why am I doing this? I'm afraid of a delay in loading graphics in my game.
The maximum image size will be no more than 1 MB.

Second - load sprites to objects when i need an object.
Place object in my room and using script like

Code:
//set position
main_logo.x=10;
main_logo.y=10;
//set sprite
main_logo.sprite_index=sprite_add("main_logo_spite.png", 1, 0, 0, 0, 0);
//set depth
main_logo.depth=-1;
Which way is better?

2) Can i create objects from the code? Like "create_object(my_new_object);" Or it is bad idea and i must allways create objects using GMS2 editor?

3) I can create instance using "instance_create_depth" function. I can create this instance in my RoomCreationCode. So it will be created once? No matter how many times I visit the room...

4) What will happens to memory (video memory, CPU load etc.) when player played a game?
Is it true that - the more rooms the user will visit, the bigger amount of memory and CPU resources needed? In the first room we create 3 instance and load 3 sprites. In second 2 instance and load 2 sprites.
So now we have in our memory 5 instance and 5 sprites. Or we allways need to destroy instance?
Has GMS2 a garbage disposal mechanism or not? How should we act?
(In delphi - List.free or my_object.destroy. In php unset($my_var) to optimize memory usage when we need it)
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
1) When i developing the game, i use some images, objects, instances. The volume of my graphics (images) will be about 100-200 megabytes. So i need to load it in my game.
I created objects and place objects in my room. Now i need to load sprites.

I see two ways.

First - load all sprites to all objects at the begining of my game. All at once.
Create loading_room with a progress bar, load graphics and change progress bar value.
Why am I doing this? I'm afraid of a delay in loading graphics in my game.
The maximum image size will be no more than 1 MB.

Second - load sprites to objects when i need an object.
Place object in my room and using script like
Both of these are bad in GMS 1.x and 2.x because each load is an extra page. The preferred strategy is to use texture groups --- tessellating things that show up together into as few pages as possible. This cuts down on the number of loads and distinct pages when you do need to load.

2) Can i create objects from the code? Like "create_object(my_new_object);" Or it is bad idea and i must allways create objects using GMS2 editor?
No. Almost every time someone wants to do this, they don't need to. Either they've mixed up objects with instances, or they've botched their data model.

3) I can create instance using "instance_create_depth" function. I can create this instance in my RoomCreationCode. So it will be created once? No matter how many times I visit the room...
No, every time you visit the room the instance is created anew. Room Creation Code runs every time you visit.

4) What will happens to memory (video memory, CPU load etc.) when player played a game?
Is it true that - the more rooms the user will visit, the bigger amount of memory and CPU resources needed? In the first room we create 3 instance and load 3 sprites. In second 2 instance and load 2 sprites.
So now we have in our memory 5 instance and 5 sprites. Or we allways need to destroy instance?
That's only true when the rooms are persistent. All non-persistent instances are removed upon changing rooms. Even with persistence involved, memory is the most immediate consequence, CPU negligibly so. CPU won't be involved much until you get into RAM thrashing territory or if there's heavy setup work in the new room.

Again, non-persistent instances are destroyed in 2 ways --- by being directly destroyed or by changing the room. When either one happens, the instances are taken care of. Quit penny-pinching individual sprites, think in terms of groups of sprites.

Has GMS2 a garbage disposal mechanism or not? How should we act?
(In delphi - List.free or my_object.destroy. In php unset($my_var) to optimize memory usage when we need it)
The garbage collector covers only non-persistent instances (when they are destroyed or when the room changes), as well as numbers, strings and arrays. Virtually everything else allocated at runtime, in particular data structures and graphics/sounds loaded at runtime, are manually collected.
 
U

User

Guest
The preferred strategy is to use texture groups
Is it possible hardly more in detail? How to use texture groups? What is their practical advantage?
I know how to create sprites (using GMS2 editor) and connect it to objects. I know how to load sprites from included files.
And Tools->Texture Groups - what is it?
I read https://www.yoyogames.com/blog/23/optimizing-your-games-in-gamemaker-studio graphics->texture pages and understand that GMS2 create 1 page for many images.
Fewer loads and pages - is good. But



I see there my sprite0. I create this sprite using GMS2 editor. And import image - so it precompiled (image in exe file or in resources) image. I'm right? It is bad.
So i can use Texture Groups only with precompiled resources? But i have a 100-200 megabytes of images...
 
Top