1

I would like to rotate long image representing hand of a clock. I have following code:

    val hand = Image(handBitmap).apply {
        scaledHeight = 50.0
        scaledWidth = 400.0
        anchor(.0, 0.5)
        addUpdater {
            rotation =  Angle.fromDegrees( rotation.degrees + 1)
        }
    }

I expected result like on this image:

enter image description here

but I got this:

enter image description here

What should I change to achieve a hand of clock like effect?

aQuu
  • 565
  • 8
  • 18

2 Answers2

2

The code seems correct, and seems to work properly with the latest version of KorGE. Which version of KorGE are you using?

enter image description here


As discussed in discord:

The problem was that the anchor point is set to the left, center of the image, while the image itself has a gap:

enter image description here

By adjusting the anchor point (that is a ratio to something that fits the end of the arrow, should fix the issue)

In the case of this image an anchor of anchor(.09, 0.52) could work:

enter image description here

Note also that you can open the debugger by pressing F7 inside the window to actually see the bounds of the image, the anchor point, and the AABB bounds to debug this kind of issues.

Hope this was helpful!

soywiz
  • 438
  • 3
  • 8
0

The problem looked more like this:

        o
        |
o------- -------o
        |
        o

It occurs when I set scaledHeight and scaledWidth.
Finally setting scale(1.0) helped.

aQuu
  • 565
  • 8
  • 18