Strange image scale issue in 2D localscale output

Hi,

This is my first post to a forum ever, so please accept my apologies if I have done this incorrectly. Basically, I am building a game which is essentially a slideshow. The game has some code within the FixedUpdate function to up or down scale an image so that it fits the entire screen:

// within the start function
sH = Camera.main.orthographicSize * 2;
sW = sH / Screen.height * Screen.width;

// within fixed update function
if (sW != sRenderer.bounds.size.x || sH != sRenderer.bounds.size.y)
sRenderer.transform.localScale = new Vector2 (sW / sRenderer.bounds.size.x,
sH/ sRenderer.bounds.size.y);

This code worked without any issues when using NPOT images. However, upon finalising the game I decided to use POT images to improve performance, game size and compile time. The code scaled images correctly for resolutions of 1024x768 (NPOT) and 1024x1024 (POT). However, for 1024x512 (POT) it seems to have an issue. The localscale assignment seems to maintain some kind of aspect ratio, which was a behaviour unseen for other resolutions. The effect is that the image flickers between original scale to scaled incorrectly back and forth. The new Vector2 line presents the correct scale quantities to achieve the screen resolution, but due to this strange behaviour of the localscale function, the second image scale operation (height) also alters the first image scale operation (width) causing the if statement to never be satisfied. I have tried searching for an answer on other forums and read the function references to look for any kind of aspect ratio locking. This behaviour did not occur for an NPOT of 1024x768 which leads me to believe it could be due to the way POT images are handled, as they do not require pre-processing before displaying. Any suggestions would be greatly appreciated?

Thanks for reading.

If you’re are using 4.6 or higher you should just use the Canvas to do the scaling for you by setting UI scale mode to scale with screen size. This way you position your images the way you want and they should scale well.