cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.17k stars 7.05k forks source link

Mouse cursor position on Windows platform #8536

Open minggo opened 10 years ago

minggo commented 10 years ago

Note

This issue is migrated from here. It was created at 2014/09/03 14:04:14 +0000

Description

Not sure if this is a Windows only problem.

In 3.2/3.3 the cursor Y is flipped in desktop/CCGLView.cpp or desktop/CCGLViewImpl.cpp

// in onGLFWMouseCallBack, onGLFWMouseMoveCallBack and onGLFWMouseScrollCallback float cursorY = (_viewPortRect.origin.y + viewPortRect.size.height - mouseY) / _scaleY;

These caused two problems: 1) Similar to Touch the cursor should be in UI points, otherwise it cannot be used in Director::convertToGL() in MouseEvent and cannot be used with Node::convertToNodeSpace()

2) The range of possible cursor X values is different from the range of possible cursor Y values For example if my screen size is 960x640 EventMouse::getCursorX() will return [0, 959] but EventMouse::getCursorY() would return [1, 640]

// the possible fix could be:(fix the first problem only in my case) float cursorY = (_mouseY - viewPortRect.origin.y) / scaleY;

justinboswell commented 9 years ago

I ran into this issue as well in 3.3. The fix in the description works perfectly.

bwaresiak commented 9 years ago

I bump this with the same problem: It happens for me on Mac OS X 10.10.2, using CC2D-x v3.4.