Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 mike9b · Jan 22, 2016 at 04:41 PM · 2dspriteimageresolutionscale

Adjust overlay position for different resolutions

I use a sprite as background with the anchors set to stretch vertically and center horizontally: alt text There are other sprite overlays I manage in code with different size than the background. Such an overlay should always be positioned at a specific location in relation to the background image and scale properly. They should produce the same result I would get when the background and overlay would be just one image with the size of the background. I haven't been able to figure out how to do this best. To visualize what I intend to do:

alt text Left bottom is the background with the overlay and I know its position and size for the unscaled background. I can set the values for the overlay with overlay.rectTransform.sizeDelta and overlay.rectTransform.position. The problem is the bottom right side which is a different game resolution so the background height got scaled down and less of the left and right borders is visible. I don't know how to set the anchors or calculate the position and scaling for the overlay to get it positioned correctly in relation to the background and new resolution.

tmp1.png (1.2 kB)
Comment
Add comment · Show 4
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
avatar image hexagonius · Jan 22, 2016 at 09:15 PM 0
Share

you didn't say how it should look on a different aspect than the one you designed it for. btw. you shouldn't need to code a single line if the layouting was done right.

avatar image mike9b hexagonius · Jan 23, 2016 at 07:37 AM 0
Share

It should always look like the background and overlay are one image. So it should behave for every situation like it would when I design the background with 1920x1080 inside a graphic program and add the overly directly there to save both as one background image ins$$anonymous$$d of two images. The merged background image would get then the anchor settings mentioned at the start.

I have multiple different sized overlays which change later in the game so my assumption was I will probably have to adjust it every time in code when the overlay changes.

avatar image hexagonius mike9b · Jan 23, 2016 at 09:52 PM 0
Share

There are several ways to position something in relation to something else. Should the overlay orient itself to the backgrounds upper left corner? Or the side? $$anonymous$$aybe the center? Is the downscale of the background in the vertical direction, and the cut off in the horizontal direction the way you want the background to behave? 16:9 just isn't the same as 4:3 or any other aspect, so how exactly do you want it to look like, not thinking of it in absolute numbers but relative information like "10% of the total width from left", or "always 50 pixels in from the upper left corner in both directions"

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems assigning sprite's images 1 Answer

doubt with pixels per unit 1 Answer

How to realize Image.fillAmount with Sprites in game? 0 Answers

Photoshop drawings loose quality in Unity? 1 Answer

Handling Multiple Resolutions in 2D? 0 Answers


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