I did read some threads about how to get Cursor Pos in cocos2dx, etc…
This should only work on Windows
Now heres some code for you:
void GetWindowPos(HWND hWnd, int *x, int *y)
{
HWND hWndParent = GetParent(hWnd);
POINT p = {0};
MapWindowPoints(hWnd, hWndParent, &p, 1);
(*x) = p.x;
(*y) = p.y;
}
Needed to get exact view position (the black box)
And NOT the hole windows, with bar etc.
In your Update, or where you wanna have the position do this:
POINT point;
if(GetCursorPos(&point))
{
int x = point.x;
int y = point.y;
int positionX;
int positionY;
GetWindowPos(CCEGLView::sharedOpenGLView()->getHWnd(), &positionX, &positionY);
x-= positionX;
y-= positionY;
CCLog("Mouse Pos: %i %i", x, y);
}else{
CCLog("Something wrong");
}
You can also save it in an CCPoint if you need,
CCPoint cursorPos = ccp(x,y);
Just add this somewhere after “y~~= positionY;”
Have fun, and you can easily make an “MouseMove” Event with that.
**PS:
Care, this is the position from origin TOP-LEFT
NOT Bottom-Left **
Bottom-Left Addition:
<pre>
y~~= CCDirector::sharedDirector()->getWinSize().height;
You may add this to cocos2dx wiki if you wan’t