Why are the first seconds of my game so choppy?

I'm having some issues with my latest game-attempt. It runs fairly smoothly, although I have to say it's pushing against the 30 fps mark, which it sometimes dips below - especially when touch events are registered - but the start of the game is really terrible! The first three seconds everything is choppy as hell, and the frame-rate seems to be about 5 fps tops.

Is this a Corona issue, with too much going on in the startup code of Corona itself? I'm not seeing this in Objective-C or Cocos2D apps, but this could of course be due to good programming of the programmers, not just the framework.

Is this something you have workarounds for? It seems like not introducing everything at the same time on screen helps, but the again at the start of a level you do sort of need everything to spawn almost simultaneously.

In another project I've put a menu screen in front of the first level specifically to offload the stress a bit during app startup, but then in that menu screen even a simple button rollover is laggy. In my last game I'm doing the same (just one button on an otherwise empty screen, that launches the game), but there it just seems do postpone the problem, with hiccups occuring when you push the button and the level starts.

I try to structure my level-start code well, with several steps in a seemingly good order (SetupArrays, then LoadMap, then SetupSprites with lots of drawing calls, and lastly SetupEventListeners is called with a delay of 100 to give the app some time to rest) but this doesn't seem to help that much. Until now my best results are just waiting 2-3 seconds when the level starts, and then gameplay is more or less fluent, but you can hardly ask the same from your gamers, huh?

Any tips or similar experiences?

thanks,
Thomas

Hi Thomas,

I've actually never had this happen to me, even with some fairly heavy physics stuff - what kind of device are you testing on?

Can you give your memory and texture usage a look, please? (You can use this code, copy and paste);

1
2
3
4
5
6
7
8
9
10
local function monitorMem(event)
     collectgarbage("collect")
     
   print( "\nMemUsage: " .. (collectgarbage("count")/1000) .. " MB")
   print("Texture Usage " .. system.getInfo( "textureMemoryUsed" ) / 1000000)
       
   return true
end
 
Runtime:addEventListener("enterFrame", monitorMem)

Could it just be the assets loading?

Let me combine both Peach's and Danny's questions/suggestions into another one?

How big are your textures?

Are you loading big textures and having Corona have to resample them down to fit the needed size?

If you're loading a bunch of graphics and 44Khz sounds and Corona is having to crunch all of that, its going to pound the CPU until its done.

I've helped several people where they load in really big graphics, suitable for tablets and then use Corona to scale them down to what is needed. If you're on an older device like an iPhone 3G or 3Gs that doesn't have a ton of memory and a slower CPU (or even the simulator since it defaults to a 3G), having to make your app deal with Retina/HD graphics is overkill. Its why Corona SDK supports the selection of the appropriate graphics with the @2x prefix.

Hi and thanks for the replies.

To sum things up: it's on a iPhone 3G device. Textures and sounds are not big. Here's the list:

- a 512 x 512 px image
- a 480 x 320 px image
- a 48x96 px image
- a 48x96 px image

- 4 wavs in mono, 44100 kHz, all under 1 second long
- 1 wav in mono, 44100 kHz, 3 seconds long.

So, the texture and audio file sizes don't seems so big, right?

Danny, you mention the assets loading as a possible cause. I was under the assumption that the graphics assets obviously load before they are displayed, so they can't be held responsible for slowdown if there is memory available, right?

Then there's the audio. How is audio loading handled? I though the code block would be executed 'line per line' (I'm oversimplifying, I know, but bear with me) so the delay due to audio file loading would be before graphics is displayed, since this is how code is structured. If however the audio engine loads stuff in the background this could be the cause of the problem. Any info on how Corona handles this? If this error would be the cause then I can work around that, I guess.

The only other causes I can think of are:
1) the adding of the touch and enterframe eventlisteners to the runtime (the only two event-listeners. Is it 'faster' or more efficient to attach the touch listeners to my tiles-displayGroup?)
2) some code that always runs when you start an app or start playing sounds, or start using the "sprite" module, so something to do with Corona framework.
3) some external non-Corona related processes, like bluetooth or trying to make a wi-fi connection, but I'm practically ruling this out since the slowdown is not at the start of the app, but at the start of the level.

I'm going to send you my project code in a PM. I am not expecting you to check it out, so feel free to just leave it as is, but if you want to take a look, please do!

The interface is simple:
- start app
- press the white square (this is the temporary "start game" button)
- left and right half of screen make the player move. Another touch on the opposing side makes the player jump.
- as you will hear, it's a sort of music based platform game in a VERY early phase.

Thanks!
Thomas

p.s. Rob, when you say Corona is 'crunching' images and sounds do you mean just loading, or resizing internally - since I don't resize anything?

Hmmm.. Any way to send private messages? I don't want to put all my code out there just like that. Share some and help out, yes, share all, no.

views:2111 update:2011/10/11 8:57:46
corona forums © 2003-2011