- Home /
Screen Space - Camera lag when zooming
Hello, I'm trying to make a GUI using the Canvas tool for a 2D game. The game is supposed to support multiple resolutions, so I figured Screen Space - Camera would be the best option, since it keeps the same format no matter what resolution.
The problem is, when I zoom in or out there is a small delay with the GUI. This doesn't happen when I use Screen Space - Overlay, but I have no idea on how to use it to support different resolutions. I've seen that some people had similar problems, but I didn't find any solutions. Does anyone know how to solve this? Either by making Screen Space - Overlay support many resolutions or stopping the lag on Screen Space - Camera or another solution I might have not been able to think.
The code snippet for the zoom is the following:
if (Input.GetAxis("Mouse ScrollWheel") > 0){ // forward
debugMessage = "mouse foward";
newOrthgraphicSize = Mathf.Max(mainCamera.orthographicSize-0.3f, 4);
mainCamera.orthographicSize = newOrthgraphicSize;
}
Thanks in advance!
If you mean changing field of view, clipping distance etc. of camera when you say zoo$$anonymous$$g, it is supposed to delay. If UI kept redrawing for every frame it would lag so UI doesn't redraw every frame but with a delay. However there should be a redraw function for you to call manually if you want.
I change the camera by changing its orthographic size (I put the code snippet in the question, now). I'll look into this redraw function. What I don't understand is why doe it not lag when I move the camera, only when I zoom it. And also, why does it work with Screen Space - Overlay.
The lag is because when you set the orhographic size of the camera, all transformation matrices are recalculated. You should look for other solutions.
Answer by rakkarage · Feb 22, 2015 at 05:08 AM
put the tileMap (or thing you zooming on new layer)
make new camera set to only show that new layer
remove that layer from old camera
change orthographicSize on new camera
fixed. no lag cuz the shit that was lagging back to normal scale is not even being scaled at all anymore
I gave up on the canvas and went another way. I can't test it anymore, but I'll select it as a good answer because it makes sense =)
Your answer
Follow this Question
Related Questions
make the canvas fit my game size i want 0 Answers
How do I draw simple shapes? 1 Answer
How does Bounds.Encapsulate() work? 2 Answers
Don't move unless in BoxCollider2D (C#) 1 Answer
Showing random image from folder on my U.I. canvas by script 0 Answers