Drag And Drop How to make my sprites and animations less impactful as possible on my games performance?

Hello everybody!
It's been a long time since my last "OMG PLEASE H4LP MEEE" thread, just because during the past years I gained
more experience using this program. Sadly, I'm not even close from being an average programmer, so I came
here to ask for some help, again.

My main problem has always been animations and sprites: sometimes because they were too big, or too "heavy",
leading to the inevitable crash or malfunctioning of my game.
Recently, the "An error as occured while running the game" error message, popped out again, and I'm pretty sure that
it has something to do with my sprites and animations. No big deal, I'll just restart making the whole game and sprites as
always to improve.

But the question is: how could I improve on this? I mean, how could I avoid the return to the problem of "memory" everytime?
My default resolution is 960x540, so my animations are based off it.
Have you got any suggestion?

Thanks alot!
 

Nidoking

Member
So, just to make sure:
You have a game that works perfectly, no problems.
You add a sprite resource, and don't make any other changes.
The game is now broken.

Is that how it works, or is it possible that some change that you made to integrate the new sprite or animation into the game could be causing the problem?
 
So, just to make sure:
You have a game that works perfectly, no problems.
You add a sprite resource, and don't make any other changes.
The game is now broken.

Is that how it works, or is it possible that some change that you made to integrate the new sprite or animation into the game could be causing the problem?
I just literally added a new sprite. Nothing else.
This thing somehow broke the game.

I used a normal sprite sheet, just like I did for the others.
 
Well, that sprite size seems extremely large, if you have animations with multiple sprites that size and you're using GM 8, it's no wonder at all that the program is having trouble. Why have sprites that are so much larger than the resolution you work with (960x540)?
 
Well, that sprite size seems extremely large, if you have animations with multiple sprites that size and you're using GM 8, it's no wonder at all that the program is having trouble. Why have sprites that are so much larger than the resolution you work with (960x540)?
It's a sprite sheet. Is not a single sprite.StarPunch! 2.png
 

Homunculus

Member
As long as it's split up into subimages, and not as a single image, I see no problem with this size. Have you tried importing a different image with the same size and split the same way? Even just with a solid color, to exclude that the image itself is the problem. GM8 is really old now though, if it's something related to the program itself (or it's compatibility with windows 10, for example) and not your assets, it could be very difficult to fix or find the actual cause
 
Last edited:
As long as it's split up into subimages, and not a single image, I see no problem with this size. Have you tried importing a different image with the same size and split the same way? Even just with a solid color, to exclude that the image itself is the problem. GM8 is really old now though, if it's something related to the program itself and not your assets, it could be very difficult to fix or find the actual cause
Keep in mind that the image I just uploaded is the 50% of the original size, due to the fact that the forum doesn't allow me to upload bigger images.
By the way, I tried a sprite with the same size, and the error popped up. ¯\_(ツ)_/¯
 

Homunculus

Member
The most important thing though: are you importing the image as a single sprite, or do you actually split it up into subimages before trying to run the game? Have you tried splitting it before importing?
 
Part of the problem with using an outdated version of a program is that you're going to be on your own for the most part with any bugs, etc. Not many people use GM 8 and also help out in the programming sub-forum. If GM 8 has the ability to manually handle texture pages and you've tried out Homunculus' suggestions, you might have to see if manually loading and unloading the images yourself helps. However, I have no idea how you'd go about doing that with drag and drop in GM 8, I kind of doubt it'll have the functionality without using code.
 
The most important thing though: are you importing the image as a single sprite, or do you actually split it up into subimages before trying to run the game? Have you tried splitting it before importing?
I'm not sure what you mean for "splitting", but when I add a sprite I always do this:

Create Sprite > Edit Sprite > Create from Strip/Add from Strip > And choose the various frames I need from the image

Part of the problem with using an outdated version of a program is that you're going to be on your own for the most part with any bugs, etc. Not many people use GM 8 and also help out in the programming sub-forum. If GM 8 has the ability to manually handle texture pages and you've tried out Homunculus' suggestions, you might have to see if manually loading and unloading the images yourself helps. However, I have no idea how you'd go about doing that with drag and drop in GM 8, I kind of doubt it'll have the functionality without using code.
I'm up to use some code if you explain me how that code works.
I usually use codes for minor things, the rest is drag-n-drop.
 
Having a look at the GM8 manual, I can see that there's no sprite_prefetch() or sprite_flush() functions, which means your only option is sprite_add(fname,imgnumb,removeback,smooth,xorig,yorig) (found here: http://gamemaker.info/en/manual/409_01_sprites). It doesn't specifically say in the text for that function, but I would assume that each sprite added that way will get it's own texture page (this is how GMS2 and 1.4 function and I assume the previous versions are in line with that), which can mean some slowdown if you're adding a lot of sprites that way. Each time a sprite needs to be drawn, the computer has to fetch the texture page that it is stored on; normally, GMS will automatically add as many sprites as possible to each texture page, to limit the amount of page swaps it needs to do, however, when manually adding sprites, there's no way to coalesce the added sprites into as few texture pages as possible, so there will be as many texture pages, and thus texture swaps, as there are sprites.

I don't know how GM8 handles it's error messages, but it's a little weird that you're getting simply "An error as occured while running the game" as information. Is there a console that logs information each time you start up your game? Often times people who aren't experienced miss important bits of information from the console when they get strange errors in GMS. If there is no console and the problem does really have to do with adding too many sprites then the reality is the answer is going to be that you have to upgrade to GMS2.
 
Having a look at the GM8 manual, I can see that there's no sprite_prefetch() or sprite_flush() functions, which means your only option is sprite_add(fname,imgnumb,removeback,smooth,xorig,yorig) (found here: http://gamemaker.info/en/manual/409_01_sprites). It doesn't specifically say in the text for that function, but I would assume that each sprite added that way will get it's own texture page (this is how GMS2 and 1.4 function and I assume the previous versions are in line with that), which can mean some slowdown if you're adding a lot of sprites that way. Each time a sprite needs to be drawn, the computer has to fetch the texture page that it is stored on; normally, GMS will automatically add as many sprites as possible to each texture page, to limit the amount of page swaps it needs to do, however, when manually adding sprites, there's no way to coalesce the added sprites into as few texture pages as possible, so there will be as many texture pages, and thus texture swaps, as there are sprites.

I don't know how GM8 handles it's error messages, but it's a little weird that you're getting simply "An error as occured while running the game" as information. Is there a console that logs information each time you start up your game? Often times people who aren't experienced miss important bits of information from the console when they get strange errors in GMS. If there is no console and the problem does really have to do with adding too many sprites then the reality is the answer is going to be that you have to upgrade to GMS2.
Screenshot (264).png
 
Does that happen exactly the same way when you run it in debug mode? Put a breakpoint on the very first line of code that will run in the game and see if it reaches that point when debugging (though, I have a feeling that the breakpoint won't pop seeing as it doesn't look like it's left the loading bar and entered the game proper before the error pops).
 
Does that happen exactly the same way when you run it in debug mode? Put a breakpoint on the very first line of code that will run in the game and see if it reaches that point when debugging (though, I have a feeling that the breakpoint won't pop seeing as it doesn't look like it's left the loading bar and entered the game proper before the error pops).
I always launch the game in debug mode, and no it doesn't fix it.
I just tried one ancient suggestion that one guy of the forum game me some eons ago: using the cropping tool on the animations.
And it worked, the game managed to finally open even with the new texture.
That's why I think that is a memory problem.
 
Any other advice?
For instance, is it a problem if I copy and paste the frames in the sprite editor to make the animation longer?

Example:
[1][2][3] = 3 frames
[1][1][1][1][1][1][2][3] = 8 frames

Does that weights on the game's performance?
 

Homunculus

Member
That's something you should avoid in general, if you want to make the animation longer, just use the image_speed variable to a more appropriate value.
 

Homunculus

Member
It applies to the whole animation. You can limit the loop to only a subset with some GML, but with drag & drop the easier thing you can do to achieve the same effect is actually creating a separate sprite for every animation, and changing the sprite when required.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Is this something that only happens with this specific project, or with any project, provided that the environment and reproduction steps (same-ish scale of existing sprite resources already existing and one of those gigantic sprite sheets being added) remain the same?

For example, does the same happen in a copy of your game where you remove everything but the sprites and the first room?


I'm unsure exactly how sprite loading is handled in GM8, but in the worst case, all of them will be pre-loaded at game start. If this is the case, your game may run into problems if you run out of memory to load those graphics into.

I don't think this has been asked yet, so: How much RAM and VRAM does the device you're running this on have?

Oh, and
Game Maker is just like a woman: it tells you that something's wrong, but it doesn't tell you what.
I wholeheartedly disagree with this and I expect you to know why. ;P
 
It applies to the whole animation. You can limit the loop to only a subset with some GML, but with drag & drop the easier thing you can do to achieve the same effect is actually creating a separate sprite for every animation, and changing the sprite when required.
Creating separate sprites weights on the performance or it's irrelevant? You never know, that's why I ask.

Is this something that only happens with this specific project, or with any project, provided that the environment and reproduction steps (same-ish scale of existing sprite resources already existing and one of those gigantic sprite sheets being added) remain the same?

For example, does the same happen in a copy of your game where you remove everything but the sprites and the first room?


I'm unsure exactly how sprite loading is handled in GM8, but in the worst case, all of them will be pre-loaded at game start. If this is the case, your game may run into problems if you run out of memory to load those graphics into.

I don't think this has been asked yet, so: How much RAM and VRAM does the device you're running this on have?
It happens on every project with big sprites. So 80% of the times. But don't worry, GM8 is abit dumb, but I'm dumber on programming, so I don't assume that it's all its fault.
Anyway, as I said earlier, it works if I remove those sprites even in the original project. So I'm 100% sure that it would work on a different backup too.
About the sprite loading, I'm pretty sure that all the sprites are pre-loaded, sadly...

Oh, and
I wholeheartedly disagree with this and I expect you to know why. ;P
Congrats then ma'am. Good to hear that you are not as childish as the other girls I met.
Atleast I hope so.
 

TsukaYuriko

☄️
Forum Staff
Moderator
... in GM8, at least. In GMS, dynamically loading sprites may lead to performance issues as they will all be put on separate texture pages, which can mess with performance depending on how and when those sprites are drawn later on.

That doesn't strictly mean you'd get worse performance in GMS... just that you'd miss out on the performance increase the system in question would provide.

It happens on every project with big sprites. So 80% of the times. But don't worry, GM8 is abit dumb, but I'm dumber on programming, so I don't assume that it's all its fault.
Anyway, as I said earlier, it works if I remove those sprites even in the original project. So I'm 100% sure that it would work on a different backup too.
About the sprite loading, I'm pretty sure that all the sprites are pre-loaded, sadly...
So what are your specs? The way you put it makes it sound very likely that the issue is a lack of memory in one way or another, but it doesn't hurt to double-check.
 

I don't see what the problem is...?

Perhaps the sum of the game's assets is too large? I don't know if there's a "hard limit."

OR like @TsukaYuriko said it could be a RAM issue.

Edit: Wait a minute. Can GM8 open .gm81 files? Let me know if not, and I'll get on my laptop. I have the Mark Overmars version of GM8 on it. I'd be happy to take a look at your project if you want me too... but that may not be necessary. All I did was convert the image to a strip image suffixed with _strip21 and it auto-magically imported it as 21 different frames.

I stretched the image to 2x scale to make sure that it worked at 3928x1690 as well as at 1964x845. Both images are included in the example linked above. No manual editing is required. I don't think that GM8 can do that, but if you send me the full resolution image I can do it with GMS2 and send you back a high-quality one. Although, there are probably free tools online to do the same. If I remember correctly legacy GM played nicely with GIF images.

Here's a zip with the .gm81 and both _strip21 images. See what happens if you use these instead.


"An error as occured while running the game"
Nothing more or less. Game Maker is just like a woman: it tells you that something's wrong, but it doesn't tell you what.
I, too, thought this to be true when I was a young man.

As an old man, I've come to realize that they were telling me what was wrong; I just didn't understand what I was hearing.

- - -

Edit 2: I decided to research this, and found this post. I learned a few new things from it.
 
Last edited:
... in GM8, at least. In GMS, dynamically loading sprites may lead to performance issues as they will all be put on separate texture pages, which can mess with performance depending on how and when those sprites are drawn later on.

That doesn't strictly mean you'd get worse performance in GMS... just that you'd miss out on the performance increase the system in question would provide.


So what are your specs? The way you put it makes it sound very likely that the issue is a lack of memory in one way or another, but it doesn't hurt to double-check.
Yeah sorry. I have 12 GB of Ram and an Nvidia graphic card.
I can usually handle lots and lots of bigger games, so it always sounded weird to me that it was my performance. I blamed my "coding" instead.
 

I don't see what the problem is...?

Perhaps the sum of the game's assets is too large? I don't know if there's a "hard limit."

OR like @TsukaYuriko said it could be a RAM issue.

Edit: Wait a minute. Can GM8 open .gm81 files? Let me know if not, and I'll get on my laptop. I have the Mark Overmars version of GM8 on it. I'd be happy to take a look at your project if you want me too... but that may not be necessary. All I did was convert the image to a strip image suffixed with _strip21 and it auto-magically imported it as 21 different frames.

I stretched the image to 2x scale to make sure that it worked at 3928x1690 as well as at 1964x845. Both images are included in the example linked above. No manual editing is required. I don't think that GM8 can do that, but if you send me the full resolution image I can do it with GMS2 and send you back a high-quality one. Although, there are probably free tools online to do the same. If I remember correctly legacy GM played nicely with GIF images.

Here's a zip with the .gm81 and both _strip21 images. See what happens if you use these instead.


Edit 2: I decided to research this, and found this post. I learned a few new things from it.
Thank you so much kind man, I'll make a few tests and I'll answer you as soon as possible.
I'll also try to send you the project of GM8, maybe you can check if there are any mistakes to correct in the future ones.

I, too, thought this to be true when I was a young man.

As an old man, I've come to realize that they were telling me what was wrong; I just didn't understand what I was hearing.
And... what if the girl never even told you that "somethings wrong"? Even if you could clearly see that something was wrong and
why the hell I'm talking about these things in a programming forum tho. Let's just get over it and take that quote as a stupid childish pun.
 
Any other advice?
For instance, is it a problem if I copy and paste the frames in the sprite editor to make the animation longer?

Example:
[1][2][3] = 3 frames
[1][1][1][1][1][1][2][3] = 8 frames

Does that weights on the game's performance?
Create Event
GML:
image_index = 0;
image_speed = 0;

alarm[0] = 6;
Alarm 0
GML:
event_user(0);
Other / User Defined / User 0
GML:
image_index+=1;

var _index;

_index = image_index;

if _index != -1 {
    switch (_index) {
  
        case 0:
            alarm[0] = 30;
            _index = -1;
            break;
          
        case 1:
            alarm[0] = 15;
            _index = -1;
            break;
          
        case 2:
            alarm[0] = 15;
            _index = -1;
            break;
        case 3:
            alarm[0] = 30;
            _index = -1;
            break;
          
        case 4:
            alarm[0] = 30;
            _index = -1;
            break;
          
        case 5:
            alarm[0] = 30;
            _index = -1;
            break;
                      
        case -1:
            alarm[0] = -1;
            break;
          
        default:
            alarm[0] = 5;
            break;
    }
}
 

otterZ

Member
Hi, I'm using GM2 and the sprites in my game are large. I found that sometimes, the odd sprite (1 in 40ish) were somehow corrupted files and they crashed the game. A non-sensical error message would pop up including advice about a 'carbon driver' not being installed, or whatever . . . anyhow, I got around this problem by first binning the corrupted file (sprite, sprite sheet, animation or whatever it is) then outputting the animation again and every time the new image (same image but saved to the desktop from the image editing software again) would work.

So in a nutshell, maybe try binning the corrupted sprite sheet (if it is corrupted), make another png file or whatever from whatever image editing software you are using (or load it up into Gimp or something and re-save it to your computer to have a new copy of the same image to try.

Using sprite_prefetch can be handy to preload an image before a level, although for sprites with 60+ large images like I'm using it does take time to load them and this can stall the game.

I also found that the performance of the computer used really has a big impact on how the sprites load. For instance . . .

My iMac which I bought in Nov 2019 has a 6-Core Intel Core i5 processor and a Radeon Pro 560X 4GB GPU - with this unit there was a performance hit loading sprites making it glitchy, but the real problem was that it suffered with overheating in hot weather due to the design of the iMac that's designed to be sleek (but totally rubbish for cooling with heavy processing work).

My PC (which was literally half the price compared to the iMac) has a Risen 5 3500 processor and a GeForce GTX 1616 6GB GDDR5 GPU - the large sprites run very smoothly with no noticeable performance hit and the tower stays relatively cool even in hot weather.

It sounds like your sprites are even bigger than mine . . . which makes me feel very insecure . . . ;)

Hope any of this helps :)
 

I don't see what the problem is...?

Perhaps the sum of the game's assets is too large? I don't know if there's a "hard limit."

OR like @TsukaYuriko said it could be a RAM issue.

Edit: Wait a minute. Can GM8 open .gm81 files? Let me know if not, and I'll get on my laptop. I have the Mark Overmars version of GM8 on it. I'd be happy to take a look at your project if you want me too... but that may not be necessary. All I did was convert the image to a strip image suffixed with _strip21 and it auto-magically imported it as 21 different frames.

I stretched the image to 2x scale to make sure that it worked at 3928x1690 as well as at 1964x845. Both images are included in the example linked above. No manual editing is required. I don't think that GM8 can do that, but if you send me the full resolution image I can do it with GMS2 and send you back a high-quality one. Although, there are probably free tools online to do the same. If I remember correctly legacy GM played nicely with GIF images.

Here's a zip with the .gm81 and both _strip21 images. See what happens if you use these instead.



I, too, thought this to be true when I was a young man.

As an old man, I've come to realize that they were telling me what was wrong; I just didn't understand what I was hearing.

- - -

Edit 2: I decided to research this, and found this post. I learned a few new things from it.
Ok, it's been quite a while and I tried what you suggested me.
No, it doesn't change at all. I guess it's because the images are not cropped and because of the copy pasted frames made with the Image Editor.

I tried to "time" the sprites instead of copy pasting, and it's kinda good! Yes, I take twice as more time and confusion, but it works.
Now I've remade ALL of the sprite sheets a bit smaller and compact. Most of them now are 25% smaller, even with new animations.

I just need to learn how to not make GM load every single sprite at the start of the game. Not only because is stupid as hell, but because I organized the sprites in terms of "need" for the level.
So it would be great if someone would teach me how to do that.
Thanks guys, you're awesome.
 
Top