Search Unity

Pixel zoom problem

Discussion in '2D' started by healingjjam, May 13, 2019.

  1. healingjjam

    healingjjam

    Joined:
    May 13, 2019
    Posts:
    2
    Hi
    There was a problem developing the 'pixel by numbers' game.

    It is a phenomenon that when you zoom the image to fill the color by pixel, the image gets bigger and the pixel coordinates change at some moment.

    This phenomenon only appears on Samsung Galaxy s10.

    When you use zoom, you can increase the scale of the transform. However, zooming using the camera's orthographic will produce the same result.

    I changed the zoom target. As a result of testing, the above phenomenon appears regardless of UI Image, RawImage, and 2D object Sprite.
    It also has no association with the pixels per unit, and the FillterMode and WrapMode of the texture are not related either.

    Attach the code used for the test.
    After creating a texture for the image, use the slider to scale the image.

    I want to know the cause of this phenomenon and solve it.
    I need your help.


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3.  
    4. public class test : MonoBehaviour
    5. {
    6.     public Transform target;
    7.     public Slider slider;
    8.  
    9.     private void OnGUI()
    10.     {
    11.         GUI.Label(new Rect(50, 50, 100, 100), Camera.main.orthographicSize.ToString(), new GUIStyle() { fontSize = 50});
    12.         float width = (target as RectTransform).sizeDelta.x;
    13.         GUI.Label(new Rect(50, 150, 100, 100), (target.localScale.x * width).ToString(), new GUIStyle() { fontSize = 50 });
    14.     }
    15.     private void Awake()
    16.     {
    17.         Image image = target.GetComponent<Image>();
    18.         Texture2D texture = new Texture2D(100, 100)
    19.         {
    20.             filterMode = FilterMode.Point
    21.         };
    22.         for (int i = 0; i < texture.height; ++i)
    23.         {
    24.             for (int j = 0; j < texture.width; ++j)
    25.             {
    26.                 texture.SetPixel(j, i, Random.ColorHSV());
    27.             }
    28.         }
    29.         texture.Apply();
    30.         image.sprite = Sprite.Create(texture, new Rect(0, 0, 100, 100), Vector2.one * 0.5f);
    31.         image.SetNativeSize();
    32.  
    33.         slider.minValue = 1f;
    34.         slider.maxValue = 150f;
    35.     }
    36.  
    37.     public void OnValueChanged()
    38.     {
    39.         target.localScale = slider.value * Vector3.one;
    40.     }
    41. }
     

    Attached Files:

  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    Are you using the pixel perfect package? If not, try the pixel perfect package.
     
  3. healingjjam

    healingjjam

    Joined:
    May 13, 2019
    Posts:
    2
    As you said, I tried the pixel perfect camera on the pixel perfect package, but unfortunately it didn't work.

    This phenomenon only appears on Samsung Galaxy s10.
     
    Last edited: May 14, 2019