Why cocos2d-x 2.2 uses so many resources in windows?

Why cocos2d-x 2.2 uses so many resources in windows?
0.0 0


Hello, Developers!

I don’t know why my empty project uses so many resources.

I have Visual Express C++ 2010, cocos2d-x-2.2 and WindowsXP-SP3.


Thanks for replying!


It seems that almost all the cocos2d-x Win32 applications use about 50~100 of CPU. Maybe this is a problem of cocos2d-x itself.
I tried to modify the cocos2d-x(I’m using 2.0.4) code and made my application work using only 0~5 CPU. And here is what I did, I hope it will help you.

In your 2dx\platform\win32 folder, find CCApplication.cpp and open it.
Add #pragma comment(lib, "winmm.lib") after NS_CC_BEGIN.
In CCApplication::run() function, find while (1) and modify it to this:

while (1)
    if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        // Get current time tick.

        // If it's the time to draw next frame, draw it, else sleep a while.
        if (nNow.QuadPart - nLast.QuadPart > m_nAnimationInterval.QuadPart)
            nLast.QuadPart = nNow.QuadPart - (nNow.QuadPart % m_nAnimationInterval.QuadPart);

    if (WM_QUIT == msg.message)
        // Quit message loop.

    // Deal with windows message.
    if (! m_hAccelTable || ! TranslateAccelerator(msg.hwnd, m_hAccelTable, &msg))

Now re-compile the cocos2d-x DLL and use it in your application.

I’m sure that if you use cocos2d-x 2.0.4, it will work. But I think it’s the same in the 2.2 version.


It uses up those resources running on meaningless loops. The good thing is that cocos2d-x will be able to calculate fps value for each single frame accurately. Change sleep(0) to sleep(1) in shiqinglv post will do but you will notice a drop in fps measurement around 4 frames. However, if you accumulate the frame number rendered each second, you will still get a value of 60.


Thanks for replying!

But this code isn’t working in v2.2. I have too little fps and high cpu usage.

I try to download and use v.2.0.4, but it’s not working too. I have some errors (libBox2D.lib) while i try to run default project.


did you rebuild the whole thing? you have to rebuild the cocos2d-x library


You should rebuild the cocos2d-x project as zhi liang teoh said after modifying the code. You should also copy the re-built DLL to your project’s Debug.win32 or Release.win32 directory.

The libBox2D.lib library works well on other computers and the default fps is 60.0 but it is 1.6 in your screenshot. It’s really strange… I think perhaps it’s because something was not correct there. Maybe you’re running too many programs?


Thanks for replying!

shiqing lv wrote:

…Maybe you’re running too many programs?

zhi liang teoh wrote:

did you rebuild the whole thing? you have to rebuild the cocos2d-x library
Is it right?


Dear Sam Sky,

Yes, you’re right. But after rebuilding, please copy the rebuilt libcocos2d.dll and libcocos2d.lib and libcocos2d.dll.intermediate.manifest to the project’s .win32 or .win32 folder (depends on which mode Visual Studio is under), and then run it again.

This is a screenshot of the mode display of VS2008 (it’s a little different in VS2010). It’s under Debug mode, so we should copy files from cocos2d-2.0-x-2.0.4\Debug.win32 to HelloWorld\Debug.win32 this time.

And here is what it did on my computer.

(Did I explain clearly?)

Please tell me if it works. Thank you!