x


LoadImageIntoTexture on iPhone from the device disk

Hello all,

I am loading a texture from the iphone disk but I am always getting a question mark or black texture. On the editor works perfect. Here is my code:

WWW www = new WWW("file://" + ConfigGame.GetiPhoneDocumentsPath() + "/ExtraLevels/World3/WorldSelectionWorld4.png");
    m_TextureWorld[3] = new Texture2D(256, 256, TextureFormat.RGB24, false);
    www.LoadImageIntoTexture(m_TextureWorld[3]);

What am I doing wrong? The texture is a png and in RGB24 and everything just looks fine!!

more ▼

asked Apr 14 '11 at 09:36 AM

barbur gravatar image

barbur
97 2 3 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You need to wait for the download to complete -- even though the file is on your local disk, there is still time involved to access the file system and load the texture, and the WWW class goes through its normal asynchronous operations.

You should run the code fragment above in a coroutine, and "yield www;" to wait for it to finish.

See the docs for more info.

more ▼

answered Apr 14 '11 at 05:03 PM

yoyo gravatar image

yoyo
6.5k 25 39 84

Thanks now it is working! I read in some forum thread that if the www file you are downloading was from a local path we do not need to yield, but we need it!! thanks :)

Apr 15 '11 at 07:06 AM barbur

Glad it worked. Please mark this as the correct answer, thanks!

Apr 15 '11 at 03:19 PM yoyo

I know this is very old, but I'm already using the yield command, and it still return me a black texture (only on iOS; on Mac editor it's working fine)...

Mar 08 at 02:35 PM DanjelRicci
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2275
x544
x10

asked: Apr 14 '11 at 09:36 AM

Seen: 1665 times

Last Updated: Mar 08 at 02:35 PM