- Home /
How to load a sprite via WWW on IOS?
Texture 2D temp = new Texture2D(0,0);
WWW www = new WWW(pathtofile); //"pathtofile" references to a .png file.
yield return www;
temp = www.texture;
sprite = Sprite.Create(temp, new Rect(0,0,temp.width, temp.height), new Vector2(0.5f,0.5f));
Why this code works on OS X, but it doesn't on IOS? When i try to load this sprite on OS X - it seems ok, but on IOS i see a small question mark. Could someone explain me - why?
And this on the other hand works on IOS but is awfully slow:
byte[] imgdata = System.IO.File.ReadAllBytes(pathtofile);
temp.LoadImage(imgdata);
sprite = Sprite.Create(temp, new Rect(0,0,temp.width, temp.height), new Vector2(0.5f,0.5f));
Btw - if i am correct the core of the problem is the texture format - but I have no idea how to work around that. I've also tried www.LoadImageIntoTexture(temp) but to no avail.
I have also noticed that the code to load sprite via WWW returns ARGB32 format, but on IOS its RGB24 and the sprite doesn't show. What can I do with this?
The best way I've found is to use WWW.textureNonReadable.
I think maybe part of the problem is you're creating an unnecessary Texture2D with no size first. You can create the sprite directly from WWW.textureNonReadable.
$$anonymous$$y best guess is there's something wrong with your path. In my game I put all the .png in the Strea$$anonymous$$gAssets folder and use this for the path:
WWW www = new WWW(System.Uri.EscapeUriString("file://" + System.IO.Path.Combine(Application.strea$$anonymous$$gAssetsPath, file)));
Answer by -Rix- · Aug 16, 2014 at 09:00 AM
Okay, I've found out, that my problem was indeed path. I've copied my old code and for IOS i had a different path - cuz for System.IO.File u dont need "file://" and for "www" u do need it, so to summarise: I've added "file://" at the start, and everything is ok. I just didnt thought it might be the problem, cuz there were no exceptions, and i didnt catch any nulls from the function output.
when i remove the metal API ,my image will not all show ,why?
Your answer
Follow this Question
Related Questions
How to load app without developer license 1 Answer
iOS crash with "Memory pressure" error - too many sprites? 0 Answers
Level load times are off the chart unacceptable 1 Answer
Lowest common denominator of saving game information 0 Answers
the XML file doesn't work when i install the app from the app store 0 Answers