korlibs / korlibs/korge

onMouseDrag only gives mouse button state on start and end

Open
#1,240 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
3k
Forks
148
Avg merge
13h 44m
Merged PRs (30d)
1

Description

I need to detect when the right mouse button is being held down each frame on a particular container, however the `onMouseDrag` event is only telling me what mouse button is being pressed on the first and last events, but not on the drag events in-between.

```
gameContainer.onMouseDrag {
// This is only true when the button is pressed and released, not as it's being held down.
if(it.mouseEvents.button.isRight) {
// do something
}
}
```

The same is true when I use an updater to check it every frame myself.

```
addUpdater {
// This is only true ON the frame the click happens, not while it's being held.
if(gameContainer.mouse.button.isRight) {
// do something
}
}
```

Now, what's interesting is that it works perfectly when I check the `Scene` input directly like this:

```
addUpdater {
// This is true every frame while the mouse button is down.
if(input.mouseButtonPressed(MouseButton.RIGHT)) {
// do something
}
}
```

However, that won't work for me because I need this to only trigger on the `gameContainer`. How do I check for a mouse button being held on a specific container every frame?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the behavior with the gameContainer.onMouseDrag and addUpdater examples, then compare them with input.mouseButtonPressed(MouseButton.RIGHT) on the Scene. Trace how mouseEvents.button and gameContainer.mouse.button are updated during drag events; done means a container-specific check reports the right button as held on every frame.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.