I’ve faced the problem with simple clicks on my Scene.
When I’m running next code within my scene:
auto mouseClickListener = EventListenerMouse::create();
mouseClickListener->onMouseUp = [this](cocos2d::Event* event){
EventMouse* mouseEvent = dynamic_cast<EventMouse*>(event);
// debug mouseEvent data here
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(mouseClickListener, this);
and click on my window frame I received data:
topmost pixel:
mouseEvent->getLocation().y returns me value of window frame height (which I set in AppDelegate.cpp ~ e.g. 600) instead of 0 as I understand from guides;
mouseEvent->getLocationInView().y returns me 0 (according to my sizes: instead of 600?).
when I click on lowermost pixel:
mouseEvent->getLocation().y returns me x2 value of window frame height (e.g. 1200);
mouseEvent->getLocationInView().y returns me a negative value of window frame height (e.g. -600);
Issue is related only to Y coordinate. X coordinate works as I expect (most left pixel X is 0, most right is equal to my frame width). As you may understand it does not allow me to click on my sprites within the scene. Could you please advice me what I’am doing wrong? Thanks!
@Musab, thanks for your reply. Could you please provide me with example of code? As I understand dispatcher listens Scene in my example. What parent node I should use instead of this in such case?
sorry i don’t use c++ or cocos2d-x i was bored and i thought i knew the problem but when you do this with js and just use this it doesn’t work so i thought it would work for you to listen to its parent but i don’t know how you would do that good luck
Following your advice I have compared my AppDelegate.cpp with original test file on cocos2d-x git and I have found out that the problem was caused by 1 missing row: