Hi, I’ve just started using new canvas system and just on the start got an issue. I’ve created simple canvas with panel and image as it’s child. Canvas is Screen space - camera mode. Everything looks great until I’d use zoom-gesture, code is taken from official tutorial:
if (Input.touchCount == 2) {
newPos = transform.position;
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
if(deltaMagnitudeDiff != 0){
camera.orthographicSize = Mathf.Clamp(camera.orthographicSize + deltaMagnitudeDiff * zoomSpeed, minZoom, maxZoom);
UpdateCamera();
}
}
UpdateCamera function just keeps camera in larger background bounds.
And here comes a problem: when I’m zooming in or out panel just like it’s “jumping”, it’s not smooth scaling. In the same moment I have simple boxes created in OnGUI method and they’re scaling perfectly smooth.
Tried with and without pixel perfect.
Just check this simple gif:
Light grey panel with fireball image is the panel, dark grey is created by OnGUI.
I’m not making any manipulation with canvas in any script.
Also for sake of this animation (I can’t use multitouch on desktop ) I’m just adding -0.2f to camera’s ortographic size:
if (Input.GetMouseButtonUp (0)) {
camera.orthographicSize = Mathf.Clamp(camera.orthographicSize - 0.2f, minZoom, maxZoom);
UpdateCamera();
}
Any idea what I’m doing wrong? Help!