• 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 Paquito · Oct 26, 2012 at 08:22 PM · androidscreensizeaspect-ratio

How can I change a sprite width based on a screen width

Hi there! I'm making a 2D videogame for Android devices and iOS, and I'm trying to make a script for resizing my assets according to the different resolutions. First I tried using GUITexture, and I could change the width of my background based on the screen width, but everything moved and the trees where floating and things like that. Now I'm using planes, so everything stays at its place, but I don't know how to adapt it to the width of the planes.

Thank you in advance!!

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 Memige · Oct 27, 2012 at 06:27 PM

You should be able to use Screen.width and Screen.height to get the current screen pixel values, then use these to calculate a scale factor that you then apply to your sprites. Be careful to uniformly scale them though, trying to account for the width and height separately will likely cause deformation in your sprites. Also be aware that, depending on the actual resolution of your sprites, larger screens may cause some pixelization due to overscaling

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 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

Related Questions

Cutoff top and bottom of screen instead of sides when changing aspect ratio 1 Answer

How can I support FHD+ Resolution in Android game? 0 Answers

How to make my game fit into my droid? 1 Answer

how to make my game for all screen please ? 1 Answer

[Android] Screen Scaling?! 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges