Is there a solution to my FPS worries?

Hello. This is my first post on the Corona forums, and it’s regarding my first app, so I figured that this was the appropriate section. In a few weeks, I used the excellent Corona documentation and resources available on Youtube to build my first ever mobile application. I’m rather pleased with the results, regardless of how simple the app is.

My worries involve a slight and occasional FPS dip that I have been noticing. It is not game-breaking, and I have only had a few people tell me that they’ve noticed it, but it is driving me nuts.

Essentially, the app involves a piggy bank swinging around on a rope, about the center of the screen, collecting coins. Which type of coin he can collect is dependent on whether or not the screen is being touched. Everything seems to be working fine, except that the rotation sometimes has a few FPS hitches, or stutters a bit.

I’m using a Runtime event listener “enterFrame” that calls my rotation() function. In this function, I increase the rotation of my piggy bank by a certain amount. This certain amount is increased every time the user collects a coin, in order to increase the rotation speed the longer you last without messing up. Is this a bad way to go about making the piggy bank object swing around the screen?

I have the FPS set to 60 in the config.lua file, though I experienced these troubles prior to that change as well. I can not say for sure if the stuttering is due to the rotation. I’m just not familiar enough with Corona to say, really. I have experienced these fps problems on the simulator and a few android devices.

I was not keen to post a link to my app for fear of advertising or something, but it is available here if you want to try and experience the issue: https://play.google.com/store/apps/details?id=com.gmail.scbdeveloper.Swing_Swine

I’ve not posted any code as of yet but if you would wish to see some I would be happy to. My theory is that trying to rotate every frame is taxing on the system or simply inconsistent.

Hi @scb5304,

Your code concept sounds OK, and using a Runtime listener is fine. It’s really hard to predict what might be causing the “stuttering” and it might not even be related to your rotation.

Here are a few things you should confirm:

  1. Are you getting any memory leaks?

  2. Have you made every function and variable local, and not global? Global variables are bad for many reasons.

  3. Have you optimized everything according to the following guide?

http://docs.coronalabs.com/guide/basics/optimization/index.html

Hopefully if you confirm all of this, you can squeek out a little more performance from your game, but remember that several Android these days are underpowered, especially the “budget” models which are not really intended for gaming or high-performance tasks.

Hope this helps somewhat,

Brent

Hey Brent,

I’m happy to hear that the general rotation concept is ok!

  1. I have no idea, to be honest, if I am getting memory leaks. The problem does not seem to occur more later in the application’s life if that makes a difference. I’m very new to Lua.

  2. Almost everything is local. I check for a global “soundIsOn” variable to cue sound effects, which I don’t have to do (and will fix) but that is only called on collision, and the stuttering occurs without this being the case.

  3. THANKS. This is an awesome guide and I can’t believe I hadn’t stumbled upon it before.

I will do my best to optimize the program and hopefully improve performance. I’m currently primarily testing my app on an Android Galaxy S4, which should be doing just fine I think, but still experiences the problem… I know that you can’t simply diagnose what the problem is, though, without looking at it, so I will press on.

Also, if you do happen to stop by again… my config.lua file has width = 640 and height = 960. I don’t remember why, I might have stolen it from a tutorial somewhere. Are these silly dimensions? I’ve attempted replacing my config.lua with the “ultimate config.lua” guide somewhere on this site, but everything was completely messed up because of how I placed everything prior… also, is dynamic image scaling a must? I don’t have anything regarding that at the moment…

Thank you very much for your support and for Corona :slight_smile:

Hi @scb5304,

Detecting and solving any memory leaks is fairly important, as the game will eventually crash if you let them go (“eventually” being a vague term, as it depends on how big the leak, the device’s total memory, etc. etc.). Anyway, do a search in these forums for how to check for memory leaks. There are several such posts, and most of them contain a convenient memory checking function similar to this one:

[lua]

local function memoryCheck()

    collectgarbage( “collect” )

    local memUsage_str = string.format( “MEMORY= %.3f KB”, collectgarbage( “count” ) )

    print( memUsage_str … " | TEXTURE= "…(system.getInfo(“textureMemoryUsed”)/1048576) )

end

timer.performWithDelay( 1000, memoryCheck, 0 )

[/lua]

As for your config w/h of 640x960, that’s absolutely fine. I actually prefer to use this size and then use “letterbox” for the scale setting, instead of using the flexible condition setup that many people use. Both are fine, and ultimately it’s up to your preference and what you find easiest to work with.

I would say that dynamic scaling is pretty important. If somebody plays your game on an HD tablet and another plays it on a smaller phone, they’ll both expect sharp, crisp graphics that appear nicely on these amazing screen that the manufacturers are giving us these days.

Take care,

Brent

Hi @scb5304,

Your code concept sounds OK, and using a Runtime listener is fine. It’s really hard to predict what might be causing the “stuttering” and it might not even be related to your rotation.

Here are a few things you should confirm:

  1. Are you getting any memory leaks?

  2. Have you made every function and variable local, and not global? Global variables are bad for many reasons.

  3. Have you optimized everything according to the following guide?

http://docs.coronalabs.com/guide/basics/optimization/index.html

Hopefully if you confirm all of this, you can squeek out a little more performance from your game, but remember that several Android these days are underpowered, especially the “budget” models which are not really intended for gaming or high-performance tasks.

Hope this helps somewhat,

Brent

Hey Brent,

I’m happy to hear that the general rotation concept is ok!

  1. I have no idea, to be honest, if I am getting memory leaks. The problem does not seem to occur more later in the application’s life if that makes a difference. I’m very new to Lua.

  2. Almost everything is local. I check for a global “soundIsOn” variable to cue sound effects, which I don’t have to do (and will fix) but that is only called on collision, and the stuttering occurs without this being the case.

  3. THANKS. This is an awesome guide and I can’t believe I hadn’t stumbled upon it before.

I will do my best to optimize the program and hopefully improve performance. I’m currently primarily testing my app on an Android Galaxy S4, which should be doing just fine I think, but still experiences the problem… I know that you can’t simply diagnose what the problem is, though, without looking at it, so I will press on.

Also, if you do happen to stop by again… my config.lua file has width = 640 and height = 960. I don’t remember why, I might have stolen it from a tutorial somewhere. Are these silly dimensions? I’ve attempted replacing my config.lua with the “ultimate config.lua” guide somewhere on this site, but everything was completely messed up because of how I placed everything prior… also, is dynamic image scaling a must? I don’t have anything regarding that at the moment…

Thank you very much for your support and for Corona :slight_smile:

Hi @scb5304,

Detecting and solving any memory leaks is fairly important, as the game will eventually crash if you let them go (“eventually” being a vague term, as it depends on how big the leak, the device’s total memory, etc. etc.). Anyway, do a search in these forums for how to check for memory leaks. There are several such posts, and most of them contain a convenient memory checking function similar to this one:

[lua]

local function memoryCheck()

    collectgarbage( “collect” )

    local memUsage_str = string.format( “MEMORY= %.3f KB”, collectgarbage( “count” ) )

    print( memUsage_str … " | TEXTURE= "…(system.getInfo(“textureMemoryUsed”)/1048576) )

end

timer.performWithDelay( 1000, memoryCheck, 0 )

[/lua]

As for your config w/h of 640x960, that’s absolutely fine. I actually prefer to use this size and then use “letterbox” for the scale setting, instead of using the flexible condition setup that many people use. Both are fine, and ultimately it’s up to your preference and what you find easiest to work with.

I would say that dynamic scaling is pretty important. If somebody plays your game on an HD tablet and another plays it on a smaller phone, they’ll both expect sharp, crisp graphics that appear nicely on these amazing screen that the manufacturers are giving us these days.

Take care,

Brent