Quick question about memory

lizosoft

Member
Hi,. when i used to use another engine a while back, my game i was making was gorgeous but i ran out of memory, it was so laggy.
What is the best method to avoid this?

Is is best to create my background for scene 1 in photoshop to make it perfect, put all my bridges, hills ect on the BG, then use invisible sprites to make the walls, floor ect..

or

make a BG in photoshop and load the sprites in GM studio 1 by 1 , example bridges as sprites.

Thanks
 

TsukaYuriko

🌠
Forum Staff
Moderator
It's less about how you create the graphics and more about how you load them - and more specifically, about how you unload them.

Create and import your graphics however it is most comfortable for you to work with them in the IDE.

After that, make sure to unload graphics that are currently not in use. You can have a theoretically unlimited amount of graphics in your project, but you can't have them all loaded at the same time.

Loading and unloading is handled via sprite_prefetch and sprite_flush. I suggest to organize your graphics into texture groups according to where they're being used, grouping graphics that are used in the same environment together, so that only the texture pages that are actually in use will be loaded at any given time.
 

lizosoft

Member
Thanks for that, is there a simple way to destroy the graphics scene when the sprite leaves that scene and load them automatically when the hero sprite enters that scene.
would this be better, because when the hero leaves the scene, i would want the scene to destroy it all anyway, and when he re-enters to load the enemies and graphics back up again.
 

TsukaYuriko

🌠
Forum Staff
Moderator
If your game was split into distinct levels which feature distinct graphics, you could use the Room End event to unload the corresponding graphics and the Room Start event to load them.
 

lizosoft

Member
If your game was split into distinct levels which feature distinct graphics, you could use the Room End event to unload the corresponding graphics and the Room Start event to load them.
oK thanks alot, ill look into this after ive created a few levels.
Im really good at photoshop so im trying to achieve a clean, polished HD platform.

what would you say is the max size of a background for a level for high quality HD graphics with ought compromising issues.
Im creating it for PC not iphones yet.
But scared incase it wont run on lower pc's but want to achieve a high q result as i have HD textures im creating
 

TsukaYuriko

🌠
Forum Staff
Moderator
When you say "textures"... are we talking about a 3D game or a 2D game here? "texture" is a term used in 3D graphics, but I'll assume this is about 2D for now as that's what GameMaker excels at.

It really depends on how your game is set up. Figure out the native resolution your game will be using and create the graphics accordingly.


Ideally, you want your native resolution to either be exactly the same as, or an even divider of, your target resolution. Your target resolution depends on what kinds of devices you plan for the game to be played on and the common resolutions those devices have right now (or will have at the point your game is planned to be released - but this may require psychic abilities and/or a bit of foresight and market prediction).

Not all displays use the same aspect ratio, though, so factor that in when deciding. You can adapt your game's camera and view dynamically according to the aspect ratio of the player's display if it doesn't exactly match your game's base aspect ratio, so that your game in turn matches the display's aspect ratio without causing distortion. Distortion is what happens when the pixels you're rendering don't translate evenly to pixels on the screen - because there are no "half pixels", the result can't be scaled and displayed evenly.


Once you know the target resolution, you can figure out the native resolution. In order to not introduce distortion during upscaling, this needs to be an even divider of the target resolution. For example, if your target resolution is 1080p (1920x1080), your potential native resolutions are 1920x1080, 960x540 (divided by 2), 640x360 (divided by 3), 480x270 (divided by 4)... and so on. There's no formula for this, you have to check and see what suits your game.

The native resolution will provide you with a frame of reference of how big your graphics will look in the game, relative to the total size of the display. At this point, you're done for the most part.


There's one more thing to keep in mind, though, and that's scaling. If there's any kind of zooming or scaling going on in your game, you have to take this into consideration if you want your graphics to retain a crisp look without individual pixels being discernible. (If you want this to be the case, this part is void.)

If the maximum amount of scaling in your game is 200%, that means you will need 200% more pixels to accomodate for the scaling, and need to downscale drawn graphics accordingly (the graphic is now twice as large, so you have to draw it at half the size). When zoomed in, the zoom factor and the downscaling factor cancel each other out, leading to it being drawn at full scale when fully zoomed in.

More importantly than making sure everything looks good at max scale, make sure that everything looks good at 100% scale. Design graphics to look good by default, not only when scaled - small details may easily get lost when you design them with the fully scaled resolution in mind, rather than the default scale.
 

lizosoft

Member
When you say "textures"... are we talking about a 3D game or a 2D game here? "texture" is a term used in 3D graphics, but I'll assume this is about 2D for now as that's what GameMaker excels at.

It really depends on how your game is set up. Figure out the native resolution your game will be using and create the graphics accordingly.


Ideally, you want your native resolution to either be exactly the same as, or an even divider of, your target resolution. Your target resolution depends on what kinds of devices you plan for the game to be played on and the common resolutions those devices have right now (or will have at the point your game is planned to be released - but this may require psychic abilities and/or a bit of foresight and market prediction).

Not all displays use the same aspect ratio, though, so factor that in when deciding. You can adapt your game's camera and view dynamically according to the aspect ratio of the player's display if it doesn't exactly match your game's base aspect ratio, so that your game in turn matches the display's aspect ratio without causing distortion. Distortion is what happens when the pixels you're rendering don't translate evenly to pixels on the screen - because there are no "half pixels", the result can't be scaled and displayed evenly.


Once you know the target resolution, you can figure out the native resolution. In order to not introduce distortion during upscaling, this needs to be an even divider of the target resolution. For example, if your target resolution is 1080p (1920x1080), your potential native resolutions are 1920x1080, 960x540 (divided by 2), 640x360 (divided by 3), 480x270 (divided by 4)... and so on. There's no formula for this, you have to check and see what suits your game.

The native resolution will provide you with a frame of reference of how big your graphics will look in the game, relative to the total size of the display. At this point, you're done for the most part.


There's one more thing to keep in mind, though, and that's scaling. If there's any kind of zooming or scaling going on in your game, you have to take this into consideration if you want your graphics to retain a crisp look without individual pixels being discernible. (If you want this to be the case, this part is void.)

If the maximum amount of scaling in your game is 200%, that means you will need 200% more pixels to accommodate for the scaling, and need to downscale drawn graphics accordingly (the graphic is now twice as large, so you have to draw it at half the size). When zoomed in, the zoom factor and the downscaling factor cancel each other out, leading to it being drawn at full scale when fully zoomed in.

More importantly than making sure everything looks good at max scale, make sure that everything looks good at 100% scale. Design graphics to look good by default, not only when scaled - small details may easily get lost when you design them with the fully scaled resolution in mind, rather than the default scale.
Yes im talking about 2d, sorry.
Excellent advice there , thankyou so much indeed, its invaluable to me and helps me so much.

Im just curious, do you think its a big memory issue if i have the camera just follow the sprite hero along the level rather than exiting and entering scenes...? like, one giant background image to cover atleast 5 or 6 scenes. ( then i can exit and destroy the scene)
By doing this, i could make the walls and floor invisible and use the BG image, or load the floor/wall/platform sprites in .

Or is it best to exit and enter the scenes with destroy all, so instead of having one large BG image, instead have 6 smaller images that he exits and enters scenes like the old spectrum 2d platforms.

( i plan to use high end graphics)

I asked a similar question, but i think taking your advice ill be using 1920x1080 joined together about 3 or 4 times to make it very long scene, but taking your advice i assume i would need to keep it native, so could be a bad idea.
 
Last edited:

TsukaYuriko

🌠
Forum Staff
Moderator
You can calculate how much of an issue it would be.

Texture pages are kept in memory in an uncompressed 32 bit per pixel (8 each for red, green, blue, alpha) format. A 1920x1080 image has 2073600 pixels. Texture pages are stored as powers of 2, so this will be 2048x2048, which has 4194304 pixels, or 134217728 bit, or 16777216 byte, or 16384 kilobyte, or 16 megabyte, if my math is correct. That's not taking any form of overhead into account, so that's the minimum, not the absolute maximum.

Depending on how many of these will be loaded at the same time, they may or may not be an issue.


For the sake of organization, you should logically split portions of your game anyway, though.
 

lizosoft

Member
Yeah good point.
Ill get a better idea when i get to that stage im sure trial and error will help me learn what's best.
Already im thinking if i can set the camera in front of the sprite and have the scene load when the camera gets near so the sprite is always in the middle of the screen, this way the next scene can load so there is no delay and essentially look like a large fluent level.
sorry this is just off the top of my head haha.
When i get to that stage ill be more able to talk about it i would think, atm im just guessing and seeking advice in advance so to speak.
 

lizosoft

Member
Just a quicky, what's the different between origin and size, and should the background sprite be 60fps or lower.
(im thinking its where the camera is fixed on the sprite, so when the sprite sits in the room, it gets put at those coordinates )
 

Attachments

Last edited:

TsukaYuriko

🌠
Forum Staff
Moderator
Size is the size.
Origin is the center point and rotational axis. When you draw a sprite at specific coordinates, the origin will be drawn at those exact coordinates.

Is your background animated? If not, it can be whatever fps you want. A static image will never animate, so it doesn't matter.
If it is animated, it is your choice at which speed it will be animated - I can't tell you that.
 
Top