• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jinl · Mar 09, 2015 at 11:53 PM · 2dlocalscale

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pendantic · Mar 10, 2015 at 12:00 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Bounds.extent relation to localScale 2D 0 Answers

My sprite is teleporting when I change my scale to -1 to flip it 1 Answer

Trying to make my Player's sword knockback the enemy without making the enemy animation freak out. 0 Answers

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Help Wanted. Switching localscale starts unwanted animation state. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges