Loading Time Issues

Hello,

I’m working on a level-based game, and I’m using the director class for my project. I have one lua file which has all the game mechanics stored in, and each level has a separate file that has the coordinates and level design stored in.

The problem is that when I test the game on my iPhone 4, it takes 20-30 seconds to load a level. If I restart or change the level, it also takes 20-30 seconds to load again. The game runs smoothly with no delay on the Corona and xCode simulator which I’m guessing means that its due to the lack of memory in the iPhone RAM.

I’m using a texture atlas to store and pack related sprites together, but I also have several texture atlas files. Is there anyway to minimize the loading time?

Thanks. [import]uid: 82699 topic_id: 22064 reply_id: 322064[/import]

Because you are using the director class, theres two things you can do. One, theres a code in the director.lua file that has a line of code that you put at the top of your files and it will help clean up memory or you need to make a localGroup and then have something like this.
local localGroup = display.newGroup ()

local initVars = function ()
localGroup:insert(name of variable)
localGroup:insert(box for example - physical object)
end
(then you would have to set up init vars by placing this under it)

initVars()
[import]uid: 122076 topic_id: 22064 reply_id: 87675[/import]

Thanks for the reply. Firstly I’m not sure which line of code you mean, maybe you can post it here? However, I’ve used the second method, but thats only useful for managing memory leaks. The problem with my code is that the sprites and background take a while to load from the start. I can hear the soundtrack playing, which I’m guessing means that the scene has already been changed, but the sprites don’t show up until 20-30 seconds afterwards. [import]uid: 82699 topic_id: 22064 reply_id: 87679[/import]

Alright well it looks like the guy who made director class actually made a different function and then removed it for some reason so I actually don’t know then. You could try messaging him on youtube or his website. Heres his youtube, http://www.youtube.com/user/RicardoRauber

And heres his email thats posted on his website.

ricardorauber[at]gmail
http://rauberlabs.blogspot.com/

*EDIT: Changed email from link, don’t want it scraped by spambots. Peach :slight_smile: [import]uid: 122076 topic_id: 22064 reply_id: 87682[/import]

I’m pretty sure it’s not a director problem. I’m just looking for a way to load the sprites faster so that I don’t have to add a loading scene between each level or every time the level is reset. [import]uid: 82699 topic_id: 22064 reply_id: 87700[/import]

@sairafi505,

You are loading sprite sheets? Or individual image files?

Also, when you exit that director scene do you free up the texture memory for the images/spritesheets in that scene?

A little more info can help in solving your problem.

Ken [import]uid: 16734 topic_id: 22064 reply_id: 87727[/import]

@KenRogoway

Yes I’m using sprite sheets and I do free them in the clean function. However, I find that the problem isn’t managing memory leaks, because when I change the scene again to the menu, the memory usage goes down again. I’ve followed Jonathan Beebe’s guide when it comes to memory management.

The only issue I’m facing is loading the scene and the sprites. When I click on the button to change the scene to the level, the current scene freezes (for two seconds on the simulator and about 20 seconds on an iPhone 4) before transitioning to the next scene.

I have about 3 sprite sheets for each level, and their size ranges from 500KB to 1MB. I have tried loading the sprite sheets in a function and calling the function from the beginning so that they could be called as a separate chunk of code before executing the other chunks, but that made little to no difference. I have noticed that games like Angry Birds and Cut the Rope have almost instant loading, but I can’t seem to go anywhere near that. Is there any way I could cache the graphics?

Thanks [import]uid: 82699 topic_id: 22064 reply_id: 87728[/import]

@sairafi505,

It sounds like you just have too much data to load it quickly.

Is any of the texture data shared between levels? If so, you can load that one time instead of for each level.

Another option is to preload multiple levels worth of data, with a loading screen, let them play ‘n’ levels, then load the next batch. This at least gives them a small hit every ‘n’ levels instead of having to each between each level.

I’m really surprised you are seeing 20-30 seconds to load 3MB of data. If they are spritesheets they should load a lot quicker than that. I load about 12MB of textures (as spritesheets) in about 12-15 seconds.

Are you using direct I/O? Using newImage()? or using Sprite Sheets? [import]uid: 16734 topic_id: 22064 reply_id: 87734[/import]

@KenRogoway

I have managed to reduce the loading time down to 9 seconds for levels with less sprites and about 12 seconds for larger levels. I guess the loading times are because I’m still new to gaming (18 years old) and I don’t really know the most efficient methods to execute certain functions, which is really disappointing because I’m very proud of the gameplay and graphics.

I think preloading multiple levels is a good idea although I don’t know how to put it in action. The way I’m loading levels is assigning the level number selected in the menu to a global variable, and then changing the scene to the game mechanics lua file, which takes in the global variable and fetches data from the level file (only fetches rather than changing scenes). When the level restarts, I use director to change the scene to an empty file that directly changes back to the game mechanics file.

I only use new image for the parallax background (~300KB), and everything else using sprite sheets.

Thanks. [import]uid: 82699 topic_id: 22064 reply_id: 87741[/import]