Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releasing the LMB outside the canvas keeps MouseInput._isPressed boolean true #17368

Closed
Remmoze opened this issue Jul 15, 2024 · 1 comment
Closed
Assignees
Labels
Bug Needs Triage Needs to be assigned by the team

Comments

@Remmoze
Copy link

Remmoze commented Jul 15, 2024

Cocos Creator version

3.8.2

System information

Windows 10

Issue description

MouseInput has a boolean inside of it called .isPressed. It is set to true when MOUSE_DOWN event is dispatched, and to false when MOUSE_UP event is dispatched. When mouse leaves the area of the canvas and LMB gets released, .isPressed boolean is stuck at true until new MOUSE_DOWN event is triggered. In my cause this is troublesome, because my game is primarily a scrollview.
When LMB gets released outside of the canvas and then the cursor returns to the game, the scrollview scrolls even though LMB is not pressed.

2024-07-15.12-51-00.chrome.mp4

For my game, I've hacked my way around the engine and trigger a MOUSE_UP when mouseleave event is dispatched.

export function enableMouseLeave () {
    // @ts-ignore
    input._mouseInput._canvas?.addEventListener('mouseleave', input._mouseInput._createCallback('mouse-up'));
}

For my game in particular, this works great, but I do realize that this might be a bad solution for other games.
Perhaps the solution should be to respond to mouseleave event only for scrollview?
Either way, that fixed my issue:

2024-07-15.13-00-31.chrome.mp4

Relevant error log output

No response

Steps to reproduce

  1. Create a scrollview the size of the game
  2. hold left mouse button to start scrolling
  3. leave the bounds of the canvas
  4. release the left mouse button
  5. return cursor to the scrollview
  6. scrollview is getting scrolled even without pressed left mouse button

Minimal reproduction project

No response

@Remmoze Remmoze added Bug Needs Triage Needs to be assigned by the team labels Jul 15, 2024
@minggo minggo self-assigned this Jul 18, 2024
@minggo
Copy link
Contributor

minggo commented Sep 29, 2024

It is fixed in #16886. Of course, should also include #17576 to fix event name conflict.

Or you can try v3.8.4 when it is fixed.

@minggo minggo closed this as completed Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Needs to be assigned by the team
Projects
None yet
Development

No branches or pull requests

2 participants