How to effectively reduce "texture Memory" ?

Greetings,

I use slices to shrink each image and lower System Memory Use.

02:56:27.554  System Memory Used: 2.046 Mb

02:56:27.554  Texture Memory Used: 280.424 Mb

02:32:06.288  System Memory Used: 2.437 Mb

02:32:06.288  Texture Memory Used: 1292.341 Mb

This is the result of loading different animation.

The former and the latter will not produce LAG phenomenon.

But the latter will make the image black.

Does this mean that I can’t do a lot of animation at the same scene?

Is there any way to solve this problem?

Thanks all. :slight_smile:

You need to provide some code or at least describe what you’ve done in more detail. The simplest steps you can do to reduce texture memory use are:

  1. use fewer and smaller images

  2. use Corona’s dynamic image scaling

  3. either try to create images that fit the power of two sizes, or put them into image sheet(s) and keep those image sheets to power of two sizes

  4. when you move between scenes, get rid of the old display objects, etc.

If the images are black, then you’ve done something wrong. I am also not sure what LAG phenomenon is, unless you just mean that the game is lagging on your device.

For general information, texture memory per image is calculated by width x height x rgba / 1024 / 1024, where width and height are always in power of two, e.g. an image that is 260x140 pixels does not fit within 256x126, so the next size that it fits is 512x256 (so the image is not optimal). If you have a PNG with an alpha channel, then the total memory used by that image is 512 x 256 x 4 / 1024 / 1024 = 0.5MB. This isn’t much, but it quickly ramps up with larger images.

I’m just saying that both are smooth for the game.

But the second makes the loaded image black.

This will only happen if Texture Memory Used > 1000 mb,and  loading other images, the new image will turn black.

Maybe I should try to remove the blank transparency.

I just want to know the maximum usage limit of “Texture Memory”, I can’t find relevant information.

In addition, dynamic image scaling will make the image quality worse. I want to avoid it as much as possible…

Oh, XeduR,

I seem to find the problem, because I am doing a full-page animation, although I slice it, each frame maintains the same width and height.

And each frame has multiple transparent unused blocks, so I cut them into smaller pieces, each of which is packaged into individual Textures to remove unused areas.

The consumption is now reduced by more than half. :smiley:

While I’m glad to hear that you’ve found your issue, I’m curious as to what you exactly mean by slicing an image. Are you just using an image sheet or what’s that about?

Also, dynamic image selection is meant to make your images look better, not worse. If you are getting worse results, then you are doing something wrong. Tell me, do you just use one size per image, i.e. do both devices with small and large displays use the same images? Because if you are, then that is going to significantly hurt lower end devices because they lack the memory to load such large images. This is what dynamic image selection is intended for, i.e. load lower resolution images for lower resolution displays and then switch to larger resolution images for larger displays, this way people with lower end devices can also play your games and everyone gets to enjoy high quality graphics.

Now, if your images are turning black AFTER that 1000MB, or rather 1024MB, then you’ve hit the device’s texture memory limit. This sounds absurd for a 2D game, but even half of that sounds very large. If you don’t mind me asking, what kind of game are you working on and how large is the game file?

EX: Split a 1920*1080 into 120*120 and a total of 144 blocks. For each piece of continuous animation in the same position, use the Texture Packer to pack it individually, so one screen is represented by 144 animations.

Dynamic image:Before I talked to other people in the forum, because my game uses a lot of animation effects, the hard disk space needs more than 1GB, so I don’t prepare a second image with lower pixels, and focus on better phone.

Because people focus on high-quality images, I don’t provide lower quality images and save hard drive space.

I am working on a 2.5D RPG multiplayer online game, and the server has other functions written almost.

It is estimated that there is now 800MB, which is quite normal for an online game (in our Play Store in Taiwan, downloaded games, you have to download other data after entering, and almost all games are >1GB)

This problem is caused by the 1920*1080 full-page animation, which makes the memory increase several times in a moment…

That sounds familiar. I’m guessing that I was actually one of the people who recommended you to ignore the low end devices back then. It’s just impossible to keep up with what advice you give and to whom on the forums. :stuck_out_tongue:

800MB for a mobile game is far from the standard size and with large games, you have to realise that you are not just competing for users’ disposable income, but also their devices’ hard drive capacity. If installing your app means that a user has to uninstall something else first, it immediately becomes a lot harder to get the user to download your game.

In your case, I’d try to reduce the texture memory usage by:

  1. optimising the animations themselves , e.g. if you have a walk or an attack cycle animation, could you perhaps do it with fewer frames?

  2. optimising the image sheets , your current image sheet size of 1920x1080 gives you space for 16 x 9 (=144) frames per sheet at the cost of 16MB of texture memory, but by changing the size to 2048x1024, you’d get 17 x 8 (=136) frames per sheet for only 8MB of texture memory used, i.e. get 8 frames less per sheet, but use half the texture memory.

  3. lazy loading only the required assets , based on how high your texture memory usage is, it sounds to me like you might be loading all image sheets regardless of whether they are needed. You can reduce the texture memory usage by only loading the assets that you require in a particular scene or for a particular event. Likewise, after you no longer need them, you can get rid of them.

Yes, you are right, but in my country, many people use the 64GB mobile phone as a basic device, even 128GB is a “real” mobile phone.

In the game forum, most players will go to see the size of the game. The bigger the game, the more rich the game, the more content and the more popular. :smiley:

Regarding the 1 point, I have done it, I changed the 25 frames to 16 frames of animation.

And the 2 point, I don’t know how this can reduce so much memory, thank you very much.

Finally, at the third point, I did want to do that, but I only tried it, because it took too much time to load each new game, but now I can only do it according to the original plan… :frowning:

The texture memory works like I explained previously.

With your 1920x1080 images, the width and height must follow the power of two sizes, e.g. 512, 1024, 2048, 4096, etc. The images will always take the next largest available. For 1920, the next one that it fits in is 2048, so there are no improvements to be made here. However, 1080 also only fits in 2048. If it were just a little bit smaller, it would fit in the 1024.

1920x1080:
2048 x 2048 x 4 / 1024 / 1024 = 16

2048x1024:
2048 x 1024 x 4 / 1024 / 1024 = 8

But still, for you to hit 1024MB texture memory usage with images that size, you’d have to simultaneously have around 60 such sheets loaded and even then you’d have plenty extra left for all other images. While I don’t encourage premature optimisation, it sounds to me like your project won’t live without some. :stuck_out_tongue:

It seems that I didn’t notice it before, but except for this full-page animation, everything else is done using Texture packer.

Just look at it, it has automatically set the texture to what you said.

This time mainly because of the full-page blood splash animation in battle.

But just after I trim it (to remove the too similar image), it will only use the original 1/10.

In general, the battle can be maintained at 600MB, but I haven’t tested how much more people will increase in multiplayer games…

The remaining super-exquisite character animations will be placed in the lobby to interact with the player (after all, there aren’t too many settings in the lobby, which can be placed in high-frame animations).

My biggest concern is that it takes 2~3 seconds to load every time the game scene change.

I don’t know if the player will be impatient.

This is the most troublesome. :frowning:

you can make a wait effect so people will not complain…in fact they will enjoy the wait :wink:

Yes, I now let it have Cutscenes, but I use the Composer syntax when testing. If I call 1000 Time, it seems that will start making animations of my new scene after 1000.

Because when I used 1000, it let me see the scene at 6000Time, when I used 10000 it appeared in 15000Time. :mellow:

I want to know how your wait effect are using “Composer” or some other way?

You’ll need to somehow stagger the loading of your scene so that you can display other things while it loads.

Say your scene loads 100 items, instead of doing this all in one block in scene:create() which means the UI becomes unresponsive and the Composer transition freezes, do one per frame or whatever number gives you a balance between loading speed and responsiveness.

OK, so I will use composer.loadScene() to load the desired scene and hide it, but it will execute Create().

I remember that Create will only be done once. (If you first go to the 1-1 level and then exit to enter 1-3, once again exit and return to 1-1, it will not execute Create)

But I didn’t see this in the documentation. Can someone explain this?

By default scenes get ‘loaded’ once and then just hidden when you go to another. However if you’ve got memory-intensive scenes, it may make sense to manually delete scenes as you go. You can do this by calling the below code in the ‘did’ phase of every scene:show().

[lua]

local previous = composer.getSceneName(“previous”)

if previous ~= “main” and previous then

      composer.removeScene(previous, false)

end

[/lua]

That’s great, I will try it.

You need to provide some code or at least describe what you’ve done in more detail. The simplest steps you can do to reduce texture memory use are:

  1. use fewer and smaller images

  2. use Corona’s dynamic image scaling

  3. either try to create images that fit the power of two sizes, or put them into image sheet(s) and keep those image sheets to power of two sizes

  4. when you move between scenes, get rid of the old display objects, etc.

If the images are black, then you’ve done something wrong. I am also not sure what LAG phenomenon is, unless you just mean that the game is lagging on your device.

For general information, texture memory per image is calculated by width x height x rgba / 1024 / 1024, where width and height are always in power of two, e.g. an image that is 260x140 pixels does not fit within 256x126, so the next size that it fits is 512x256 (so the image is not optimal). If you have a PNG with an alpha channel, then the total memory used by that image is 512 x 256 x 4 / 1024 / 1024 = 0.5MB. This isn’t much, but it quickly ramps up with larger images.

I’m just saying that both are smooth for the game.

But the second makes the loaded image black.

This will only happen if Texture Memory Used > 1000 mb,and  loading other images, the new image will turn black.

Maybe I should try to remove the blank transparency.

I just want to know the maximum usage limit of “Texture Memory”, I can’t find relevant information.

In addition, dynamic image scaling will make the image quality worse. I want to avoid it as much as possible…

Oh, XeduR,

I seem to find the problem, because I am doing a full-page animation, although I slice it, each frame maintains the same width and height.

And each frame has multiple transparent unused blocks, so I cut them into smaller pieces, each of which is packaged into individual Textures to remove unused areas.

The consumption is now reduced by more than half. :smiley:

While I’m glad to hear that you’ve found your issue, I’m curious as to what you exactly mean by slicing an image. Are you just using an image sheet or what’s that about?

Also, dynamic image selection is meant to make your images look better, not worse. If you are getting worse results, then you are doing something wrong. Tell me, do you just use one size per image, i.e. do both devices with small and large displays use the same images? Because if you are, then that is going to significantly hurt lower end devices because they lack the memory to load such large images. This is what dynamic image selection is intended for, i.e. load lower resolution images for lower resolution displays and then switch to larger resolution images for larger displays, this way people with lower end devices can also play your games and everyone gets to enjoy high quality graphics.

Now, if your images are turning black AFTER that 1000MB, or rather 1024MB, then you’ve hit the device’s texture memory limit. This sounds absurd for a 2D game, but even half of that sounds very large. If you don’t mind me asking, what kind of game are you working on and how large is the game file?