79647202

Date: 2025-06-01 04:59:55
Score: 1
Natty:
Report link

I understood the problem!

Cocos converts the mouse event to the touch event automatically, so events are propagated to the cc.layer, which are touch events.

Event listeners, in the cc.layer, listen for the mouse event.

So, basically, when I trigger the onMouseDown event on the screen, there are 2 events (onMouseDown and onTouchBegan) that are triggered.

There are several approaches to solving this problem. We can manually end mouse events in the ccui.layout. Or we can use the touch events in the cc.layer instead.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Gavin