Hi all, I have some problems related with the came...
# korge
j
Hi all, I have some problems related with the camera. Probably, I made some mistakes. I have two questions. My camera & container settings are:
Copy code
val size = 800.0
val cam = Camera(0.0, 0.0, size, size)
val container = cameraContainer(size, size) { ... }
container.camera = cam
First, I have a soccer ball image in the middle of the screen and I’m using its position to move the cam.
Copy code
container.addFixedUpdater(ConfigModule.FPS.timesPerSecond) {
    ...
    launchImmediately {
        if (match.state == State.TakingPhoto) cam.zoom += 0.02 // This line for the second question
        cam.moveTo(ballRenderer.image.x - ConfigModule.halfScreenSizeWidth / cam.zoom,
        ballRenderer.image.y - ConfigModule.halfScreenSizeHeight / cam.zoom, 1.nanoseconds, Easing.SMOOTH)
    }
}
This works but I would like to add some delay in the camera movement. For this, using
1.seconds
instead of
1.nanoseconds
I get the correct delay. The problem is that in this case, I can see the ball a bit laggy, almost two balls at the same time in the screen, maybe due to the animation. Is there another way to do this? My second question is the zoom. I would like to change the zoom in any moment but I don’t know how to do it correctly. When the match is in the
TakingPhoto
state (about 50 iterations) I take advantage of this to zoom in while the ball is stopped.
Copy code
if (match.state == State.TakingPhoto) cam.zoom += 0.02
I think this way is a mini hack. This works perfectly but I would like to choose in any moment of the match another zoom, but using an animation. I mean, if my current zoom is 1.5 and the ball position is off the soccer pitch for example, I need to change it from 1.5 to 1.0. Which is the correct way to change the zoom using an animation while is positioning in a point? Thaaaanks!
d
Mmm. Not sure about the old camera. I think korge 2.0 has a new camera that works slightly differently. Also notice that you cannot delay 1.nanosecond. In the end it delays to the next frame
j
first I render the ball and update the position
Copy code
ballRenderer.render(match.getBallPosition())
and after moving the camera. I have tested moving the camera first but the result is the same. If I use 0.1.seconds the result is worse. 1.nanoseconds is because I cannot set 0 to remove the delay. I saw this camera example here: https://github.com/korlibs/korge-samples/tree/master/camera I think this example is using korge 2.0
d
I think you should use the
follow
method to follow the ball with anchor to the center
j
I used it but the view followed was in the (0,0) position. I would not be using correctly the anchor. I’ll try it again, thanks!