Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Wisteso · Nov 16, 2013 at 11:23 PM · 2ddisplayviewportorthographicratio

Viewport ratio appears inconsistent in 2D game

I've been searching for a solution on this everywhere I can, so hopefully this isn't a "duh" thing that was in the FAQ.

The problem is that the ViewPort's handling of W over H are never consistent with the true/actual aspect ratio of my game assets. I am using the 2D workflow since this is a 2D game.

The reason I'm saying that it's inconsistent is that my "background" image is 640 by 480 which is a ratio of H = 0.75 * W (4:3), yet in order to "trick" the viewport into displaying the correct way, I need to tell it to use W = 0.59 and H = 1.0 which is definitely not correct.

Nothing I've tried has been able to fix the issue. Furthermore, the viewport gets all messed up when actually running the game (becomes more like W=0.5 H=1.0), but that appears to be a separate issue.

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
1
Best Answer

Answer by Wisteso · Nov 17, 2013 at 12:35 AM

I seemed to have solved the problem. After looking at some other posts, it seemed that ViewPort W and H are multiplied by the screen width and screen height, which would definitely explain the issues for me.

The problem is that the Inspector has no way to specify any alternative modes. Why the 2D workflow would not offer an alternative "absolute ratio" mode is beyond me, because the default mode does not work at all for "board game" type games. The fix required the following code in my start() handler...

 this.camera.pixelRect = new Rect(0, 0, (int)(Screen.height / 0.75), Screen.height);

I use 0.75 because I want a 4:3 ratio, but you would adjust this to whatever you need your ratio to be.

And then you'd want to just completely ignore what the ViewPort W and H get adjusted to as a consequence of the above code since board games don't care about resolution-dependent-ratios. (it changed mine 0.59 to 0.5904335 since 0.59 was my approximation/workaround)

Comment
Add comment · Show 4 · 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
avatar image Benproductions1 · Nov 17, 2013 at 12:40 AM 0
Share

The reason Unity doesn't have a "absolute ratio" mode, is basically because stretching is generally bad. It's not very friendly to other devices and will make your game look really bad :)

avatar image Wisteso · Nov 17, 2013 at 03:21 AM 0
Share

Sure, I get that, but stretching would be optional. Some games wont look bad with stretching, and some games are fine with black bars in the unused space.

avatar image Benproductions1 · Nov 17, 2013 at 07:44 AM 0
Share

True, however how many games do you know which acctually need this feature? It's a very little amount and Unity should rather spend their time fixing important bugs and adding useful features, rather than adding a "absolute ratio" mode you can implement yourself...

You should accept your answer btw ;)

avatar image Wisteso · Nov 17, 2013 at 09:49 AM 0
Share

I think a lot of the new 2D games that we'll be seeing will desire this feature. Any game with a fixed size viewport will want it in order to work correctly on any size screen. Anyway, thanks for the comments and the re$$anonymous$$der!

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Faking orthographic zoom by scaling positions 1 Answer

How to properly set up quad positions for 2d with an orthographic camera? 2 Answers

Water system for 2D game 0 Answers

Why Is My Orthographic Camera Not Rendering at the Full Resolution? 1 Answer

Iphone 2d camera settings 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