korge icon indicating copy to clipboard operation
korge copied to clipboard

Off-center rotation with Circle and RoundRect.

Open mimoguz opened this issue 4 years ago • 2 comments

New project, Korge 2.3.3 with below code:

suspend fun main() = Korge(virtualWidth = 640, virtualHeight = 400, bgcolor = Colors.WHITE) {
    val test = circle(radius = 20.0, fill = Colors.BLACK) {
        position(320.0, 200.0)
        anchor(0.5, 0.5)
    }

    test.addUpdater { dt ->
        test.rotation(test.rotation + 120.degrees * dt.seconds)
    }
}

Calling anchor(0.5, 0.5) should place the transform origin to view's center, right? Yet resulting motion is off-center. Furthermore, the wobble radius increases with the window size. The problem also appears when same transformation applied to a RoundRect, but doesn't when SolidRect or Image is used.

Edit: I think this is the same issue with #379.

mimoguz avatar Aug 18 '21 11:08 mimoguz

I just repro'd this.

Wierdly, when placing the circle at exactly the middle of the screen, as in your example, there was no wobble. The circle looked like it didn't move, as is expected when rotating a circle around the center.

However, the further I placed it from the center of the screen, i.e. position(0.0,0.0), the worse the wobble became.

davjhan avatar Dec 31 '21 21:12 davjhan

https://user-images.githubusercontent.com/10100613/147839789-20336892-37ed-466b-820f-1d6f4025d040.mov

davjhan avatar Dec 31 '21 21:12 davjhan