Jump to content

Strange behavior of zoom script


Recommended Posts

Hi Guys,

I'm experiencing a strange behaivior when zooming in and out. While i can grasp(a little) what is happening I have problems solving it.

When an object in my game is clicked it is zoomed in. I accomplish this by using

game.camera.follow(object, Phaser.Camera.FOLLOW_LOCKON);

to keep the object in the center of the view. Then i set:

game.world.scale.setTo(x, y);

every tick + 0.01 until I hit 1(or close to it)

This worked as a cool zoom feature for some time.

Now its starting to give me trouble.(I think after changing the wrld bounds and unbounding the camera, but i tried and can't make it work again.)

On the first zoom step the object is jumping a few pixels right and down.

On the last zoom step the object is juming back to the center.

I checked whats happening step by step (by decreasing the tickrate) and to me it looks like the game is doing the following:

tick 1

follow with camera

zoom in (object is jumping)



tick 2

follow with camera

zoom in (object is jumping)



Thats why at the first tick it is jumping and at the last one its jumping back into position.

Is there a way to turn around the order? so that its first followed and then directly rendered?

This should be possible somehow in the render function, but i just can't get my head around it.


Thanks for your help,



Link to comment
Share on other sites

Found the Problem after some testing.

game.camera.follow(object, Phaser.Camera.FOLLOW_LOCKON);

Does basicly the same thing as

game.camera.setPositionXY(object.x, object.y);

in every tick. But this is wrong when scaling since its locking to the position of the object in the previous scale. correct would be:

game.camera.setPositionXY(object.x * newScaleX, object.y * newScaleY);

This solved it for me.

Zooming is now smooth as wanted.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...