korge: add rotation

16
Timo Bryant 2024-01-05 21:56:05 +01:00
parent 8d4ba39793
commit cb8867af2e
1 changed files with 12 additions and 0 deletions

View File

@ -34,6 +34,7 @@ class ViewDocument(private val document: Document) : Scene() {
var scaleFactor = 0.5 var scaleFactor = 0.5
var offset = Point(0.0,0.0) var offset = Point(0.0,0.0)
val moveFactor = 50.0 val moveFactor = 50.0
var rotationFactor = 0.0
scale(scaleFactor) scale(scaleFactor)
suspend fun zoom(amount: Double) { suspend fun zoom(amount: Double) {
@ -60,6 +61,15 @@ class ViewDocument(private val document: Document) : Scene() {
easing = Easing.EASE_IN_OUT) easing = Easing.EASE_IN_OUT)
} }
suspend fun rotateBy(amount: Double){
rotationFactor += amount
tween(
this@sceneMain::rotation[rotationFactor.degrees],
time = 0.1.seconds,
easing = Easing.EASE_IN_OUT
)
}
keys { keys {
down { key -> down { key ->
when (key.key) { when (key.key) {
@ -69,6 +79,8 @@ class ViewDocument(private val document: Document) : Scene() {
Key.DOWN -> moveY(-moveFactor) Key.DOWN -> moveY(-moveFactor)
Key.RIGHT -> moveX(moveFactor) Key.RIGHT -> moveX(moveFactor)
Key.LEFT -> moveX(-moveFactor) Key.LEFT -> moveX(-moveFactor)
Key.E -> rotateBy(10.0)
Key.R -> rotateBy(-10.0)
else -> {} else -> {}
} }
} }