I’m looking for a way to hide the mouse pointer in cocos2d-x. Has anyone looked in to doing this before and perhaps could give me a head start in my research. I know about glutSetCursor in opengl, is there a way to use the glview to hide the cursor in that case?
Cocos2d-x 3.0 uses GLFW. You can hide mouse cursor with glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);.
But you’ll need to modify the code of cocos2d-x, since there is no API to get the window handle from the client code.
In Cocos2d-x 3.2 you can get the window handle with Director::getInstance()->getOpenGLView->getWindow().
I don’t know if it’s available in earlier versions.
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
glfwSetInputMode(glview->getWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
Just wondering if anyone has any ideas on how you could hide the mouse cursor on mac specifically but desktop in general. Id like to hide the cursor and then create my own cursor in cocos2dx.
Now in my onMouseMove event if the cursor is out of visible bounds of the screen I call my unHideCursor() function and if its in bounds I call hideCursor() function. I created a bool called cursorHidden as well. This was because every time you call [NSCursor hide] you have to call [NSCursor unhide] the same amount of times. This ovoids calling [NSCursor hide] or [NSCursor unhide] multiple times. As a matter of fact I guess I could have created a bool local to where my mouse event handlers are and not even call into Application if I don’t need to. Not sure theres really any difference. So either way now when my cursor is in bounds I just have a “cursor” sprite that follows my mouse position. Works like a charm.
It would be really nice if hiding the native cursor was an options and I didn’t have to modify these files to achieve this since my changes could get wiped out if I upgrade, but it works well enough for now!