I saw a lot of instructions how to extract screen size on mobile (glview->getFrameSize(), yes?). But I want to select correct resolution for desktop window (GLViewImpl::createWithRect("Name here", cocos2d::Rect(0, 0, ???, ???))).
How can I do that?
you want the actual screen resolution ur user is using?
windows? -> https://stackoverflow.com/questions/8690619/how-to-get-screen-resolution-in-c
It fact, I need a size of screen, on which my game’s window will be opened, to fit in it, but area, aviable for window is even better.
Is you solution cross-platform (windows+mac+linux(most important for now is linux))?
its not cross platform.
to get the screen resolution your user is using you have to use the api of the system ur user is running.
you could just use the pre compiler options in ur code to make it work without much work for you each time you want to compile for another system.
Have a look in AppDelegate. If you are looking to go full screen on desktop you have some work ahead of you because users can run different resolutions. You will need to decide how large to make your assets, etc. Take a look at design resolution.
Thank you! Last question: how can I determine system at compile time?
I found simple way to do it using GLFW: void glfwGetDesktopMode( GLFWvidmode *mode ). Do cocos2d-x use GLFW?
The code i’m use in my desktop project:
Size GameManager::getDeviceScreenSize() {
Size screenSize = Size::ZERO;
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
if (nullptr != monitor) {
const GLFWvidmode* videoMode = glfwGetVideoMode(monitor);
screenSize = Size(videoMode->width, videoMode->height);
}
else {
auto glview = Director::getInstance()->getOpenGLView();
screenSize = reinterpret_cast<GLViewImpl*>(glview)->getMonitorSize();
}
return screenSize;
}
Thank you! It is exactly what I need!
A word of warning: if you planning to get screen size BEFORE GLViewImpl::createWithRect, you must init glfw with glfwInit(), then get screen size, then shut down glfw with glfwTerminate(). On OSX you can call createWithRect without shutting down glfw, but on Win32 it will crash.