Very High Energy Consumption

What would be the major cause that there is a very high energy consumption in my game?

Button class: https://pastebin.com/saiydd2N
Shape class: https://pastebin.com/bMfyEuj3
Spriite class: https://pastebin.com/6FHBtPkz

Thank you :slight_smile:

Vec2 verts[364];
    verts[0] = Vec2(-width / 2, -height / 2 + cornerRadius);
    for (int i = 0; i < 90; i++)
    {
        verts[1+i] = Vec2(verts[0].x + cornerRadius + cornerRadius * cos((i + 180) * M_PI / 180), verts[0].y + cornerRadius * sin((i + 180) * M_PI / 180));
    }
    verts[91] = Vec2(width / 2 - cornerRadius, -height / 2);
    for (int i = 0; i < 90; i++)
    {
        verts[92+i] = Vec2(verts[91].x + cornerRadius * cos((i + 270) * M_PI / 180), verts[91].y + cornerRadius + cornerRadius * sin((i + 270) * M_PI / 180));
    }
    verts[182] = Vec2(width / 2, height / 2 - cornerRadius);
    for (int i = 0; i < 90; i++)
    {
        verts[183+i] = Vec2(verts[182].x - cornerRadius + cornerRadius * cos(i * M_PI / 180), verts[182].y + cornerRadius * sin(i * M_PI / 180));
    }
    verts[273] = Vec2(-width / 2 + cornerRadius, height / 2);
    for (int i = 0; i < 90; i++)
    {
        verts[274+i] = Vec2(verts[273].x + cornerRadius * cos((i + 90) * M_PI / 180), verts[273].y - cornerRadius + cornerRadius * sin((i + 90) * M_PI / 180));
    }

How high are your draw calls?

https://prnt.sc/tecis0

I will test thank you

Looks interesting. But yes high draw counts.

Its most likely due to the shadow and outline effects of your labels, consider bit map font as alternative.

2 Likes

Ok for verts https://prnt.sc/tepa86
but still have high consumption https://prnt.sc/tepb1w

Thank you

Can someone tell me how to use ≈20 labels ≈20 drawnode and ≈20 sprite in one scene without getting my phone burning please ? :slight_smile:

Draw node is probably your reason. Try adding all draw nodes to a single node object.

Are you breaking auto batching with labels? @stephenhurry mentioned the shadows too.

Use a for loop to create each type x 20 then add to the scene or a node

What phone are you running on?

What version of cocos2d-x?

Maybe I don’t understand the operation of cocos2d-x 4
I have an iPhone 8

Classes: https://www.mediafire.com/file/kqknlvhdj1mq4wr/Classes.rar/file

I’m trying to group nodes in many RenderTexture but labels are blured and texture is reversed in win32 but not on ios!?

Thank you for helping me!

Why did you choose RenderTexture? I don’t feel like this is a good idea. I gave you a few ways to handle this.

Disable the drawnodes and check if they are the problem. If the drawnodes are the problem, you can post here what you are doing on them, and receive more help based on what you are doing.

1 Like

Okay so when I call my shutdown function “energy leak” is stopping but I don’t understand what the problem, is the problem is simply using internet?

https://www.mediafire.com/file/t7ockpxjisdomg8/Classes.zip/file

Thank you all

Is this .zip complete? Meaning I can drop these classes in a new project and run it? If so I can try to find some time to see what happens for me.

You can drop this project in a new project and run it :
(auto download resources files with http request and connecting to my server with tcp and ump connection)
https://www.mediafire.com/file/khux7jx97ac2afc/Classes.zip/file

When I run this on Xcode (iPhone 8) I have an “energy leak” but if I close my tcp connection (by calling shutdown() in MenuScene class) the energy while be stabilized (no more overhead)

Thank you very much

I’m confused. So you don’t think it’s the sprites, labels, etc that this thread has been about? Not you think it it tcp related?

Yes it was my Shape class too but apparently he has something else. All I want to do is put an end to this energy problem! If you can give me some tips ect!

Thank you :slight_smile:

Any wireless connection will hit the battery in some way so it’s kinda natural to see higher energy consumption when you have a network connection open.
It should not be abnormally high though (if it’s even tcp related) so unless you have like 20 active connections, your culprit is somewhere else.

Ok so where do you think the problem could come from?

You would really need to completely dissect your code to find something like that. Most do not care about energy consumption and in most cases the increase is not worth the trouble of optimization.

If you are determined to find the culprit, I would suggest doing the following:

  1. Make a fresh new game app that has no graphics, no audio or anything else. Just a blank app that can run. Then implement the connection routine similar to the one you use in your game and test it. If you do not see any similar energy spikes, then connection most definitely is not your problem and the real culprit is somewhere in your graphics code.

  2. If you do observe similar energy consumption increase, try testing your game on some other phone since the phone itself could be the culprit. Also, very aggressive AV scanners that scan every open connection might be causing the energy increase by themselves so your game might not be the cause itself, but some other app that is running in the background and starts doing something when your game has an active connection.

  3. If you use many threads to do the background work, that will increase the energy consumption as more (or all) CPU cores will be used. If this is done only briefly, no problem since you get more optimization with multi threading and optimizing energy consumption here is meaningless. If you use such scenario throughout your game all the time, well, then either try lowering the number of additional threads, make them sleep if they are not used or ignore multi threading concept (not recommended) altogether if you are more concerned about energy consumption.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.