Skip to content

Commit

Permalink
fix: viewport now correctly unbinds itself from an entity
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Sep 14, 2023
1 parent 7c8fb36 commit 76cdf21
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/scene/Viewport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class Viewport
* Unbind viewport.
*/
fun unbind() {
boundX = null
boundY = null

zoomProperty().unbind()
}

Expand Down
23 changes: 23 additions & 0 deletions fxgl/src/test/kotlin/com/almasb/fxgl/app/scene/ViewportTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.almasb.fxgl.app.scene

import com.almasb.fxgl.entity.Entity
import javafx.geometry.Rectangle2D
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -32,4 +33,26 @@ class ViewportTest {

assertThat(viewport.visibleArea, `is`(Rectangle2D(300.0, 300.0, 400.0, 300.0)))
}

@Test
fun `Binding`() {
val entity = Entity()

val viewport = Viewport(800.0, 600.0)

viewport.bindToEntity(entity, 0.0, 0.0)

entity.x = 150.0

viewport.onUpdate(0.016)

assertThat(viewport.x, `is`(150.0))

// unbind
viewport.unbind()

entity.x = 300.0
viewport.onUpdate(0.016)
assertThat(viewport.x, `is`(150.0))
}
}

0 comments on commit 76cdf21

Please sign in to comment.