Bonsaiheldin

Make sprites / images ignore camera zoom

Recommended Posts

Hello there.

I have some images which have name tags on them, displaying names or quantities. The name tags are Text objects and i want them to stay of the same size independently of the camera's zoom.

Something like that exists for camera scrolling: Sprite.setScrollFactor(0) makes sprites stay at the same position on the screen, no matter where the camera's position is or where it scrolls to.

Is there something like that for zooming, too? I'm basically searching for a Sprite.setZoomFactor.

At the moment i have my own camera zoom function which fires camera.setZoom and then iterates all name tags in the game and fires Text.setScale(1 / Camera.zoom). It works, but only as long as the zoom happens suddenly, not smooth.

I've tried tweening the camera's zoom value and Camera.zoomTo. Both ways enable smooth zooming, but the name tags get distorted / pixelated when i use scaleX / scaleY tweens on them.

Is there a possibility to make them just ignore the zoom or at least a zoomTo for sprites / images?

Share this post


Link to post
Share on other sites

There's no way to stop a Game Object responding to a Camera's zoom or rotation because the display list works by taking the transform matrix for the camera and then applying it down the whole list. It can't selectively only take part of it for just some of the children.

The easiest solution I think would be to have a parallel Scene on the top of the game scene, which holds just your name tags, and position them relative to the sprites in the Scene below. Alternatively, you could use a second Camera that ignores everything other than name tags, and have the main Scene camera ignore all name tags. Then zooming the main camera won't impact the tags, because the 'tag' camera can stay as-is.

Share this post


Link to post
Share on other sites
7 hours ago, rich said:

Alternatively, you could use a second Camera that ignores everything other than name tags, and have the main Scene camera ignore all name tags. Then zooming the main camera won't impact the tags, because the 'tag' camera can stay as-is.

Thanks rich. I'm going for the approach with the second camera, it's the most straight forward one to me because i haven't worked with scenes yet. It works. 👍

I now just have to calculate the image's positions on screen to properly position the name tags as they have to take the main camera's zoom into consideration. They are now only placed where they should be when the zoom is 1 of course. What's the formula to get an object's position on the canvas, taking zoom into consideration?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.