Skip to content

Commit

Permalink
fix: FPS camera now works even when mouse buttons are pressed, closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Jul 22, 2022
1 parent f6a419b commit 804e331
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/GameScene.kt
Expand Up @@ -23,6 +23,7 @@ import com.almasb.fxgl.ui.UI
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.value.ChangeListener
import javafx.collections.ObservableList
import javafx.event.EventHandler
import javafx.scene.Group
import javafx.scene.Node
import javafx.scene.SceneAntialiasing
Expand Down Expand Up @@ -120,19 +121,19 @@ internal constructor(width: Int, height: Int,
)

if (is3D) {
input.addEventHandler(MouseEvent.MOUSE_MOVED) {
val mouse3DHandler = EventHandler<MouseEvent> {
if (isMouseGrabbed) {
// ignore warp mouse events
if (it.screenX.toInt() == mouseWarper.warpScreenX.toInt() && it.screenY.toInt() == mouseWarper.warpScreenY.toInt()) {
lastMouseX = it.screenX - window.x
lastMouseY = it.screenY - window.y

return@addEventHandler
return@EventHandler
}
}

if (!isFPSCamera)
return@addEventHandler
return@EventHandler

val mouseX = it.screenX - window.x
val mouseY = it.screenY - window.y
Expand Down Expand Up @@ -175,6 +176,9 @@ internal constructor(width: Int, height: Int,
lastMouseX = mouseX
lastMouseY = mouseY
}

input.addEventHandler(MouseEvent.MOUSE_MOVED, mouse3DHandler)
input.addEventHandler(MouseEvent.MOUSE_DRAGGED, mouse3DHandler)
}

initViewport(width.toDouble(), height.toDouble())
Expand Down

0 comments on commit 804e331

Please sign in to comment.