korge-samples icon indicating copy to clipboard operation
korge-samples copied to clipboard

How to use a Camera? sample

Open FSaurenbach opened this issue 3 years ago • 3 comments

FSaurenbach avatar Feb 11 '22 07:02 FSaurenbach

@soywiz i maybe can create a sample myself but i dont know if i should use cameraContainer Camera or Container

FSaurenbach avatar Mar 20 '22 08:03 FSaurenbach

I'd say the sample that currently covers the new camera API is this one: https://github.com/korlibs/korge-samples/blob/2ccda53ffeb5663f126b9836ab3dc74f1a5faadf/samples/tilemap/src/commonMain/kotlin/main.kt#L14

Though it is a very simple sample

soywiz avatar Apr 05 '22 18:04 soywiz

There is a weird thing in the way it works. Every view need to be the child of the camera AND the camera move in opposite direction.

        fixedSizeContainer(256,256,clip = true) {
            val camera = camera {
                val circle = circle(15.0, fill = Colors.RED)
            }

            addUpdater {
                camera.x += 1
            }
        }

The circle will move right, because camera.x += 1 is moving the view, not the camera... So, the circle will go right.

The code bellow will achieve the same effect:

       val camera = fixedSizeContainer(80,80) {
            val circle = circle(15.0, fill = Colors.RED)
        }

        addUpdater {
            camera.x += 8*it.seconds
        }

programaths avatar Apr 08 '23 15:04 programaths