Performance problem with sprites

I created a new project and there is only one sprite in the scene with the HelloWorld.png default 960x640 image. Testing it on a mediocre device gives me 50 frame rate instead of 60. However there are complex games developed with cocos2d-x(they are in cocos2d-x games) which runs smoothly and without any problem on the same device. How can I achieve a good performance like those games ?

@4li Hi , i dont know what do you mean by saying performance problem with sprites , but if you are talking about the jitter/flickering of sprite while moving in physics environment see this for fix Why jitter/jerk when following sprite with layer? (video included), cause i recently faced this issue and it worked for me also @amin13a gave some good tips here Performance / Optimization - Endless Scroll , if problem still persists would you mind explaining problem in more detailed manner , Thanks

1 Like

Thanks @bbmn16. Those links helped me to increase the FPS of my game. I noticed that creating sprites drop FPS significantly, so I decided just to change the shader of the sprites. I want to know how can I do this without memory leak. Is it the best way to do this?
And also my biggest problem still exist. As I told in my previous comment in a simple project with just only one 960*640 sprite as the background, FPS drops to 50 in a device with resolution 1280*800. Is it normal ?

@4li are you creating sprites in update loop ? i dont think creating sprite has something to do with FPS drop unless its in update loop or in game logic , you can create sprite or array of sprite while start and use it in your game logic then it would be much better , also i dont know about shaders so you should probably create a new thread with title specific to problem like 'Shader usage problem ’ or ‘FPS drop due to Sprite Resolution ?’

Silly question perhaps, but if it’s an Android device have you ensured that powersaving is turned off? I have found this drastically affect performance.

Otherwise could you post your simple 1 sprite scene code here?

Thanks for your replys @bbmn16 and @almax27. It’s my code:

bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
	auto sprite = cocos2d::Sprite::create("HelloWorld.png");
	sprite->setAnchorPoint(cocos2d::Vec2::ANCHOR_BOTTOM_LEFT);
	sprite->setPosition(cocos2d::Vec2::ZERO);
	this->addChild(sprite);
	

    return true;
}

without those four lines FPS is 60 and with them it drops to 50. Any idea ?

You aren’t doing anything unusual, so this should work fine. What device are you running this on?

Also did you check the power saving mode was turned off on the device?

I’m running this on Galaxy Tab 4 and it’s not related to power saving mode. As I told before there are complex games on the device which runs smoothly.

Try to make a Release build, not a Debug one

Thanks @ivcoder for your reply but even in release mode frame rate drops to 50.

Thanks to @jjeorijjang I solved the problem in this way. I want to know is there any side effects by setting GLContextAttrs to zero ?

Adding a custom shader for changing the hue drops the fps to 20 on Galaxy Tab 4, However it does not affect the fps on Galaxy S Duos 2 S7582 which seems to be a weaker device. Also the Galaxy S device works fine even without setting GLContextAttrs to zero. Is there any problem with Galaxy Tab 4 gpu ? Is there any way to use shaders in this device ?

Update:
It has no problem with shaders. I changed the custom shader just to generate a gradient and it works with 60 FPS:

float c = glFragCoord.y/iResolution.y;
gl_FragColor = vec4(c, 0.0, 0.0, 1.0);

However adding some complexity such as using builtin functions such as mod, step and … drops the FPS significantly. Approximately each function drops it by 5 frames.

Any idea ?