Is there any other way to load sprites? - unity3d

Hi there I was wondering if in unity there is any other way of loading sprites during game, that doesn't include using resources.load. That's because i have some large images and load seemse to be quite consuming.
Any ideas?

Stream classes can be used to control loading process instead of Resources.Load(). In this way, you can partially load a resource, stop loading, and resume the loading later. Below link will be helpful.
http://forum.unity3d.com/threads/160787-Texture-Stream-Loading

Related

Efficient way to Load the scene and Scene Render optimization

Our unity3d Most of the Scenes are too heavy. What is the right way and efficient way to load the scene.?? Please dont refer me LoadLevelAsync I have already see that! What is the best practice to load heavy scene without any problem and un-smoothness.
For which platform you are building?
The heaviest thing to load in Unity are Textures. If you are using too much of them in the scene, make sure that they are compressed and try to reduce their max size in the inspector. If you can't see any improvement, consider creating a loading screen transition after calling Application.LoadLevel("YourBigLevel").
You can add an Activity indicator if you are running the app on iOS or Android devices.

How can I speed up the loading of images from a web service?

I'm new to iPhone development. In my application, I had kept a scrollview and I have loaded the images from web service using JSON parsing. Unfortunately, it is taking too much time to load them. Do you have any suggestions on how to speed up the (down)loading?
Well there can be many routes you can take to make image loading faster but the one thing I would recommend most is utilize AFNetworking's "UIImageView+AFNetworking" category which you can find here:
http://afnetworking.com/
It loads images quickly and doesnt tie up the main thread. If you have a preloader image you want to display while it is downloading you can do that as well.
AND it's really easy:
[imageView setImageWithURL:[NSURL URLWithString:#"…"]];

What's the Best way for Lazy loading images in iPhone?

I want to know, what is the best way for lazy loading. For me, most of the applications i have used parsing and get the url from the server and put the image into the table view. So i have implemented lazy loading for improving the performance of the application. Now i want to know the best method for lazy loading images. Because i have used lazy loading into the four ways,
Lazy loading images from Apple developer.com
Implemented Asynchronous method for improving the lazy loading
Used separate main thread for handling the image downloaded.
Have used ECOImageLoadingDemo application for lazy loading.
But i have used the above four methods to achieve the lazy loading. But i want to know what's the best method for lazy loading. Which one is best for performance wise and memory wise is suitable for that?
Thanks in Advance.
Regards,
Pugal
From my experience, performance-wise and memory-wise solutions are on the opposite ends of a slider. You can move around with your solution somewhere between these two, but with the disadvantage that having the best solution performance-wise, usually means a worse solution memory-wise and vice-versa. I hope I explained this clear enough :)
Here's how I handle the problem of lazy loading images:
In my application I created ONE entity which I called GlobalImageProvider. All requests for images go through this entity. This way I have control on how many threads I use to download and I can implement a caching system (memory + local disk), all of these completely transparent to the application and with full control.
By controlling the size of the cache, I can control how quick the application feels. Performance wise, nothing compares with having an UIImage already created in memory.
Memory-wise, you can even choose to disable the cache.
Even more, I can even change the number of threads dynamically while the application is running depending on the quality of the network I have.
To make the online requests, I'm using NSURLConnection but I plan on switching to something else since I've read that it leaks memory.
On the view&controllers side, I have a AsyncImageView which is just a UIImageView that knows how to work with the GlobalImageProvider. It knows to display an activity indicator while loading and can handle the response from GlobalImageProvider.
If you know the URL of the image you want, all you need to do is add a AsyncImageView to your screen and make a request to the GlobalImageProvider with the AsyncImageView as the "handler" for that image.
If you don't like mixing data with the image views, you can add a ViewController between the GlobalImageProvider and AsyncImageView. He gets the image response and puts it in the ImageView.
That's about it, hope it helps you a bit.
You can take a look at this excellent tutorial from Peepcode in the section Bonus: KVO for Cell Images
http://peepcode.com/products/iphone-view-controllers-part-ii

Preloading assets in cocos2D

I have some assets for my game that are being loaded when the gameplay layer is loaded. I'd prefer to load them when the application launches in a loading screen, which is obviously a pretty standard thing to do.
My problem is the way in which new scenes are launched within cocos2D. Consider the following code which occurs (with some variations) in several places throughout the project:
[[CCDirector sharedDirector] replaceScene:[CCTransitionShrinkGrow transitionWithDuration:0.5f scene:[GameplayLayer scene]]];
This is the standard way of replacing the current scene with a new one. My question is, given that format, how would I pass a preloaded asset to the new GameplayLayer? Is there an accepted way of doing this in cocos2D? I have a feeling that I'm missing something incredibly simple, but as of now it's a mystery to me.
Cocos2d uses a texture cache that persists between scenes. You can preload assets into this cache in a loading scene and they will still be available from your game scene. How you load these are up to you. For images you can opt to do it asynchronously, to allow your loading scene to maintain a decent framerate and render a progress bar.
This post gets the basic idea across.
This thread may also be of use to you in that regard: http://www.cocos2d-iphone.org/forum/topic/2242
If you have your own class of assets (i.e. not a supported cocos2d image, or something), you could create your own cache singleton class (look at how the sharedManager instances of various cocos2d classes are implemented) and load your assets into that. As far as memory management goes you'd have to release those assets yourself whenever you deem necessary, but that's rather beyond the scope of this question.

Big loading times in iphone app

I'm making an openGL game for iPod/iPhone.
At start I load at once all the textures I need. At first loading times where small, but as I kept developing and adding new textures the loading times have been increasing, to the point of taking many seconds before the game start.
Recently a new problem appeared, when I build the game in the device It takes too long and the game quits. At the app is installed correctly and i can test It, but never while being connected to xcode. Sometimes even the app quits, when too many elements are dran on screen.
Right now I use 6 files , with about 2 Mbs of size in total.
Is there a form to create a loading screenor the such ?
What other meassures can I take so solve this issues ?
If you're decoding PNG files at startup using Core Graphics, I would suggest using PVRTexTool to create PVR data files instead. The contents of PVR files can be uploaded directly to OpenGL; no need to use Core Graphics to decode them.
PVRTexTool can also do neat stuff like generate mipmaps (another thing you might want to avoid at startup time) and encode to compressed formats (reducing your texture size will help too).
Besides encoding your textures as PVR-textures there are a few more solutions.
One is to defer texture loading to a later point. Let your app bring up its user interface and maybe show a progress bar to the user while you're loading your textures. This will stop iPhoneOS from killing your app.
You'll probably also need to look into what kind of textures you are creating. Some formats are much more expensive than others to create from you png:s.
As a last resort you could save your textures as uncompressed raw textures. This will make your app larger but cut down loading time.