Get device screen size?

I use Director::getInstance()->getWinSize() to get size of screen but it return:
X: 346226168 Y: 0

Why?

I use BlueStacks to test my game.

Try on actual hardware. Sometimes emulators don’t report correctly.

1 Like

Or use the emulator that comes with the Android Studio. I used it recently, and it does not have this problem.

2 Likes

I use Android Studio on windows.
Is it possible to run my game directly on Desktop without emulators. (Like libGDX)

Not if you are target\ting Android. You need an emulator or hardware. If you want to run it on Windows, you must create a Windows project.

is it not Director::getInstance()->getVisibleSize(); that returns the screen size thats what I use.

I do this:

 #ifdef USING_COCOS2DX
            auto director = cocos2d::Director::getInstance();
            setScreenWidth(cocos2d::Size(director->getOpenGLView()->getFrameSize()).width);
            setScreenHeight(cocos2d::Size(director->getOpenGLView()->getFrameSize()).height);
            setScaleFactor();
        
            if (getDebug())
            {
                log("screen width: ", getScreenWidth(), "screen height: ",getScreenHeight());
                log("scale factor: ", getScaleFactor());
            }
        #endif
1 Like