• 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
3
Question by 1nsomniac · Apr 15, 2014 at 11:00 AM · 2dspriteiphoneassets

Different Sprites for iPhone, iPhone Retina & iPad

Hi all,

I've been developing games for iOS using cocos2d-iphone for some time and don't quite understand how to provide different sprites for different devices/resolutions in Unity.

In cocos2d you simply create 3 set of assets (sd, hd, ipadhd). In other words you have each sprite/spritesheet in 3 sizes. For example if I have a background image I will have 3 files:

  1. bacgkround.png - loaded on iPhone 3GS

  2. background-hd.png - loaded on iPhone 4,4S,5,5S and iPad

  3. background-ipadhd.png - loaded on iPad Retina

I want to follow the same principle in Unity. I've been researching this for a few hours already and still didn't find a good way to do this.

The closest way to do this is suggested in this topic: http://answers.unity3d.com/questions/37118/how-to-support-retina-display.html

As far as I understand I need to do something like this in a script attached to each sprite:

 public Sprite sd;
 public Sprite hd;
 public Sprite ipadhd;
 
 void Start()
 {
    if ( /* iphone 3Gs */)
        ((SpriteRenderer)this.renderer).sprite = sd;
    else if ( /* ipad retina */ )
        ((SpriteRenderer)this.renderer).sprite = ipadhd;
    else 
        ((SpriteRenderer)this.renderer).sprite = hd;    
 }


But in this case I either need to set Sprite to none in Inspector and make Editor window simply useless or the Sprite set in the Inspector will be loaded before the Start is called, and only after that I'll load correct sprite.

Is there any official way to do this correctly?

Comment
Add comment · Show 3
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 ByteSheep · Apr 15, 2014 at 01:20 PM 1
Share

There isn't any built in way to do this, but it can be easily done by script. The script you have there should work fine but you might want to try changing the Start() function to Awake() - this should ensure that the sprite set in the inspector won't be visible before you set the new sprite.

avatar image 1nsomniac · Apr 15, 2014 at 02:12 PM 0
Share

Thanks @merry_christmas, I've managed to hack some script, if it works I'll post it later.

I've also thought about Awake, but according to documentation the object is already loaded in Awake, doesn't it mean the texture I've set in the Inspector is already loaded in memory and wasted some space/time loading?

Also it looks like I need to change camera aspect and sprite position in the script, as well as collider size if any.

$$anonymous$$aybe there is a plug-in (preferably free:)) that does everything for me?

avatar image ByteSheep · Apr 15, 2014 at 02:41 PM 0
Share

To be honest I'm not sure if the sprite set in the sprite renderer component will be drawn before the Awake function is called - but according to this page https://docs.unity3d.com/Documentation/$$anonymous$$anual/ExecutionOrder.html, it sounds like the Awake function will be called before any rendering is done. Whether this means that the sprite set in the inspector won't need to be loaded, I'm not sure.
Sorry I can't be of more help.. Normally however for simple sprites this isn't really a big issue.

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.

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

21 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 avatar image avatar image avatar image

Related Questions

2d Sprite Sheet on characters ruined in unity 1 Answer

Replace a sprite by another in every game object using it 1 Answer

Rotate the weapon sprite with a joystick 0 Answers

How to crossfade sprites with overlaid sprites 0 Answers

SpriteSheet or Mesh 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