Game is not smooth

I don’t see the point, given that you noted that you tried the cpp-tests project included with Cocos2d-x, and you still had issues with the apparent lag. It makes no sense at all. The best thing you can do is use one of your two devices to take a video recording of the other device while it’s running the cpp-tests, to show us what that lag/flickering is.

I recorded a video of the problem: https://youtu.be/DUaKKyXIq3c

I don’t see any lag or flickering whatsoever in that video. Can someone else here please confirm that too, because to me the parallax test being run on the device displaying as it’s expected to, and even the stat FPS counter is showing around 60 FPS.

@mhmtemnacr If, from your point of view, what you’re seeing is somehow not acceptable to you, then I honestly don’t know what else to say.

The lag is not noticeable in video but im experiencing the lag, especially in my game. Cpp tests is lagging a bit too. If i send the project files can you build and test it please?
@R101

Look, from what I saw, there was no issue with the cpp-tests demo that you showed in that video, so I don’t know what it is you’re seeing.

As for your game, it’s more than likely that the problem lies within your own project. If you’ve just started with this game engine, then perhaps you need to learn a bit more about how it works, and how to effectively use it. You’re welcome to post up your project somewhere and link it here in this thread, and perhaps someone could spare some time to check it out, but you can’t expect others to fix it for you.

1 Like

Sorry i couldnt find the reason of problem by myself thanks anyway

These one line responses don’t do anything to help you solve your issue. You need to give more information, and as you previously mentioned, posting a project that reproduces the behavior you’re seeing would go a long way to getting you help. It doesn’t have to be the actual project you’re working on, but just something that allows others to see what it is you’re seeing.

Yes, it looks fine to me.

ThePlatformer.zip (1.8 MB)

Can someone test this project? It has flickering problem for me, is there something wrong with code or settings. Please help me

Its not actually a lag. Screen is trembling. Its like skipping frames

A few things:

  1. Avoid using “using namespace XYZ” in header files, because they’ll affect any other files they’re included in, and you’ll end up with some name clashes down the line. Only use them in the implementation files (*.cpp etc).

  2. The actual issue isn’t so much related to skipping frames, but rather to rounding errors as a result of how the background images are being moved.

A better implementation may be this:

bool init()
{
...
    scrollSpeed = 300.f;
    sprSceneback1 = Sprite::create("bg.png");
    sprSceneback2 = Sprite::create("bg.png");
    sizeScene = sprSceneback1->getContentSize();

    sprSceneback1->setPosition(origin.x+(visibleSize.width*0.5f), origin.y+(visibleSize.height*0.5f));
    sprSceneback2->setPosition(origin.x +(visibleSize.width*0.5f) + (sizeScene.width), origin.y+(visibleSize.height*0.5f));

    this->addChild(sprSceneback1);
    this->addChild(sprSceneback2);

    this->schedule(std::bind(&HelloWorld::scrollScene, this, std::placeholders::_1), "BackgroundScroller");
...
    return true;
}
void HelloWorld::scrollScene(float dt) {
    auto pos1 = sprSceneback1->getPosition();
    auto pos2 = sprSceneback2->getPosition();

    if (pos1.x < -sizeScene.width / 2)
    {
        pos1.x += sprSceneback1->getContentSize().width * 2;
    }

    if (pos2.x < -sizeScene.width / 2)
    {
        pos2.x += sprSceneback1->getContentSize().width * 2;
    }

    float targetPos1X = pos1.x - std::abs(scrollSpeed);
    float targetPos2X = pos2.x - std::abs(scrollSpeed);

    targetPos1X = MathUtil::lerp(pos1.x, targetPos1X, dt);
    targetPos2X = MathUtil::lerp(pos2.x, targetPos2X, dt);

    sprSceneback1->setPositionX(targetPos1X);
    sprSceneback2->setPositionX(targetPos2X);
}

That should smooth out the movement, and even stop the flickering from happening. I did notice the images flicker at random times with your original code, even on the Win32 build, and that issue is no longer present with the code I pasted above.

2 Likes

Thanks. Its more smooth on Xiaomi device but lag is still present on Samsung note 3. I think its unfixable. But it became smoother than before

The lag persist in my own game :frowning:

I have a similar problem with my game. It runs smoothly on MacOS, IOS, and android. But is looking like skipping frames on windows32

The game is unplayable especially on Note 3. Im talking about my own game. Cpp tests also has the same problem.

By the way im building the game on a low spec computer. Can it cause this problem?

@arturapps Do you run win32 in fullscreen? If yes then you should check for enabling v-sync.

I installed ubuntu and built my game on linux platform. Nothing changed. I want to fix this ASAP please help me

does anyone have a small reproducible test case that shows the lag so I can test it out?

The OP posted his code a few posts up in a zip file, and I tested it with Cocos2d-x v3.17.2 as a win32 project. In this project you will see jerky movement (it flickers every now and then) when the background is scrolling to the left. No apparent reason for the jerky movement except how the movement is being calculated, which does result in errors. This is not an issue with Cocos2d-x, but with the OP’s code.

As for “lag” in cpp-tests, I can only say that I have not experienced any whatsoever, whether on Win32 or on an Android build, so I’m still not sure what the OP is referring to. This has been tested on several devices, an old HTC One M7 with Android 6 and a Google Nexus 6P with Android 8.1.

2 Likes

Thanks @R101 for the clarifications.