Hi everyone! I had a question about fps in my game.
So, when I would play about a minute of it, the fps would start dropping immensely going from 60 to around 30. I changed the game to 30 fps wondering what would happen, but now it drops to 15.
If anybody has any tips as to how I should go about fixing this, that would be great. Please ask for any more information if need be.
Thank you.
PS I am using PonyWolf’s Visual Monitor to see my FPS, Texture and System Memory, and # of Stage Objects on screen. So I could provide these values if necessary.
Also, here are the logs containing all of the above values:
Jan 21 01:11:08.299 FPS: 60 Texture Memory: 4.56mb System Memory: 1.89mb Stage Objects: 167 Jan 21 01:11:08.795 FPS: 60 Texture Memory: 4.68mb System Memory: 2.25mb Stage Objects: 239 Jan 21 01:11:09.290 FPS: 60 Texture Memory: 4.7mb System Memory: 1.59mb Stage Objects: 287 Jan 21 01:11:09.786 FPS: 60 Texture Memory: 4.7mb System Memory: 1.99mb Stage Objects: 287 Jan 21 01:11:10.282 FPS: 60 Texture Memory: 4.7mb System Memory: 2.38mb Stage Objects: 287 Jan 21 01:11:10.778 FPS: 60 Texture Memory: 4.7mb System Memory: 2.75mb Stage Objects: 287 Jan 21 01:11:11.274 FPS: 60 Texture Memory: 4.7mb System Memory: 3.09mb Stage Objects: 287 Jan 21 01:11:11.771 FPS: 60 Texture Memory: 4.7mb System Memory: 1.75mb Stage Objects: 287 Jan 21 01:11:12.267 FPS: 60 Texture Memory: 4.7mb System Memory: 2.16mb Stage Objects: 287 Jan 21 01:11:12.763 FPS: 60 Texture Memory: 4.7mb System Memory: 2.5mb Stage Objects: 287 Jan 21 01:11:13.260 FPS: 57 Texture Memory: 4.7mb System Memory: 2.91mb Stage Objects: 287 Jan 21 01:11:13.755 FPS: 60 Texture Memory: 4.7mb System Memory: 1.44mb Stage Objects: 285 Jan 21 01:11:14.250 FPS: 60 Texture Memory: 4.7mb System Memory: 1.83mb Stage Objects: 287 Jan 21 01:11:14.747 FPS: 60 Texture Memory: 4.7mb System Memory: 2.21mb Stage Objects: 287 Jan 21 01:11:15.243 FPS: 60 Texture Memory: 4.7mb System Memory: 2.49mb Stage Objects: 285 Jan 21 01:11:15.738 FPS: 60 Texture Memory: 4.7mb System Memory: 3.02mb Stage Objects: 287 Jan 21 01:11:16.235 FPS: 60 Texture Memory: 4.7mb System Memory: 1.58mb Stage Objects: 287 Jan 21 01:11:16.731 FPS: 58 Texture Memory: 4.7mb System Memory: 1.94mb Stage Objects: 287 Jan 21 01:11:17.226 FPS: 60 Texture Memory: 4.7mb System Memory: 2.22mb Stage Objects: 287 Jan 21 01:11:17.723 FPS: 58 Texture Memory: 4.7mb System Memory: 2.59mb Stage Objects: 287 Jan 21 01:11:18.219 FPS: 59 Texture Memory: 4.7mb System Memory: 3.03mb Stage Objects: 287 Jan 21 01:11:18.714 FPS: 60 Texture Memory: 4.7mb System Memory: 1.58mb Stage Objects: 287 Jan 21 01:11:19.210 FPS: 60 Texture Memory: 4.7mb System Memory: 1.95mb Stage Objects: 289 Jan 21 01:11:19.707 FPS: 59 Texture Memory: 4.7mb System Memory: 2.22mb Stage Objects: 287 Jan 21 01:11:20.203 FPS: 60 Texture Memory: 4.7mb System Memory: 2.73mb Stage Objects: 289 Jan 21 01:11:20.699 FPS: 59 Texture Memory: 4.7mb System Memory: 3.04mb Stage Objects: 287 Jan 21 01:11:21.195 FPS: 60 Texture Memory: 4.7mb System Memory: 1.59mb Stage Objects: 287 Jan 21 01:11:21.690 FPS: 60 Texture Memory: 4.7mb System Memory: 2.06mb Stage Objects: 287 Jan 21 01:11:22.186 FPS: 60 Texture Memory: 4.7mb System Memory: 2.42mb Stage Objects: 287 Jan 21 01:11:22.684 FPS: 59 Texture Memory: 4.7mb System Memory: 2.79mb Stage Objects: 285 Jan 21 01:11:23.179 FPS: 60 Texture Memory: 4.7mb System Memory: 1.47mb Stage Objects: 287 Jan 21 01:11:23.674 FPS: 60 Texture Memory: 4.7mb System Memory: 1.9mb Stage Objects: 289 Jan 21 01:11:24.171 FPS: 59 Texture Memory: 4.68mb System Memory: 2.26mb Stage Objects: 289 Jan 21 01:11:24.667 FPS: 60 Texture Memory: 4.68mb System Memory: 2.58mb Stage Objects: 287 Jan 21 01:11:25.163 FPS: 60 Texture Memory: 4.68mb System Memory: 2.83mb Stage Objects: 287 Jan 21 01:11:25.659 FPS: 59 Texture Memory: 4.68mb System Memory: 3.16mb Stage Objects: 287 Jan 21 01:11:26.155 FPS: 60 Texture Memory: 4.68mb System Memory: 1.83mb Stage Objects: 287 Jan 21 01:11:26.651 FPS: 60 Texture Memory: 4.68mb System Memory: 2.17mb Stage Objects: 287 Jan 21 01:11:27.148 FPS: 60 Texture Memory: 4.68mb System Memory: 2.56mb Stage Objects: 287 Jan 21 01:11:27.643 FPS: 60 Texture Memory: 4.68mb System Memory: 3.03mb Stage Objects: 289 Jan 21 01:11:28.138 FPS: 60 Texture Memory: 4.68mb System Memory: 2.02mb Stage Objects: 275 Jan 21 01:11:28.636 FPS: 60 Texture Memory: 4.68mb System Memory: 2.67mb Stage Objects: 287 Jan 21 01:11:29.132 FPS: 60 Texture Memory: 4.68mb System Memory: 1.89mb Stage Objects: 287 Jan 21 01:11:29.628 FPS: 60 Texture Memory: 4.68mb System Memory: 2.74mb Stage Objects: 287 Jan 21 01:11:30.125 FPS: 60 Texture Memory: 4.7mb System Memory: 3.73mb Stage Objects: 283 Jan 21 01:11:30.623 FPS: 59 Texture Memory: 4.7mb System Memory: 2.8mb Stage Objects: 271 Jan 21 01:11:31.119 FPS: 60 Texture Memory: 4.7mb System Memory: 3.87mb Stage Objects: 283 Jan 21 01:11:31.614 FPS: 60 Texture Memory: 4.7mb System Memory: 2.9mb Stage Objects: 289 Jan 21 01:11:32.110 FPS: 60 Texture Memory: 4.7mb System Memory: 4.55mb Stage Objects: 289 Jan 21 01:11:32.608 FPS: 57 Texture Memory: 4.7mb System Memory: 3.52mb Stage Objects: 287 Jan 21 01:11:33.104 FPS: 60 Texture Memory: 4.7mb System Memory: 5.22mb Stage Objects: 287 Jan 21 01:11:33.599 FPS: 60 Texture Memory: 4.7mb System Memory: 4.11mb Stage Objects: 287 Jan 21 01:11:34.094 FPS: 60 Texture Memory: 4.7mb System Memory: 2.85mb Stage Objects: 287 Jan 21 01:11:34.591 FPS: 60 Texture Memory: 4.7mb System Memory: 4.88mb Stage Objects: 287 Jan 21 01:11:35.089 FPS: 58 Texture Memory: 4.7mb System Memory: 3.59mb Stage Objects: 287 Jan 21 01:11:35.585 FPS: 60 Texture Memory: 4.7mb System Memory: 5.85mb Stage Objects: 287 Jan 21 01:11:36.082 FPS: 60 Texture Memory: 4.7mb System Memory: 4.67mb Stage Objects: 287 Jan 21 01:11:36.575 FPS: 60 Texture Memory: 4.7mb System Memory: 3.37mb Stage Objects: 287 Jan 21 01:11:37.073 FPS: 60 Texture Memory: 4.7mb System Memory: 6mb Stage Objects: 287 Jan 21 01:11:37.571 FPS: 60 Texture Memory: 4.68mb System Memory: 4.7mb Stage Objects: 283 Jan 21 01:11:38.065 FPS: 60 Texture Memory: 4.68mb System Memory: 7.53mb Stage Objects: 287 Jan 21 01:11:38.563 FPS: 53 Texture Memory: 4.68mb System Memory: 6.28mb Stage Objects: 287 Jan 21 01:11:39.057 FPS: 60 Texture Memory: 4.68mb System Memory: 4.98mb Stage Objects: 287 Jan 21 01:11:39.556 FPS: 60 Texture Memory: 4.68mb System Memory: 8.24mb Stage Objects: 287 Jan 21 01:11:40.081 FPS: 60 Texture Memory: 4.68mb System Memory: 6.81mb Stage Objects: 287 Jan 21 01:11:40.593 FPS: 60 Texture Memory: 4.7mb System Memory: 5.42mb Stage Objects: 287 Jan 21 01:11:41.091 FPS: 60 Texture Memory: 4.64mb System Memory: 8.71mb Stage Objects: 289 Jan 21 01:11:41.590 FPS: 46 Texture Memory: 4.64mb System Memory: 7.53mb Stage Objects: 289 Jan 21 01:11:42.097 FPS: 60 Texture Memory: 4.64mb System Memory: 5.99mb Stage Objects: 287 Jan 21 01:11:42.634 FPS: 30 Texture Memory: 4.7mb System Memory: 4.62mb Stage Objects: 287 Jan 21 01:11:43.159 FPS: 48 Texture Memory: 4.7mb System Memory: 8.42mb Stage Objects: 283 Jan 21 01:11:43.670 FPS: 59 Texture Memory: 4.7mb System Memory: 6.85mb Stage Objects: 287 Jan 21 01:11:44.162 FPS: 60 Texture Memory: 4.68mb System Memory: 5.35mb Stage Objects: 279 Jan 21 01:11:44.740 FPS: 36 Texture Memory: 4.7mb System Memory: 9.77mb Stage Objects: 289 Jan 21 01:11:45.283 FPS: 60 Texture Memory: 4.7mb System Memory: 8.3mb Stage Objects: 287 Jan 21 01:11:45.890 FPS: 60 Texture Memory: 4.7mb System Memory: 6.62mb Stage Objects: 289 Jan 21 01:11:46.428 FPS: 40 Texture Memory: 4.7mb System Memory: 11.23mb Stage Objects: 287 Jan 21 01:11:47.029 FPS: 56 Texture Memory: 4.7mb System Memory: 9.54mb Stage Objects: 291 Jan 21 01:11:47.604 FPS: 60 Texture Memory: 4.7mb System Memory: 7.79mb Stage Objects: 287 Jan 21 01:11:48.167 FPS: 33 Texture Memory: 4.7mb System Memory: 6.06mb Stage Objects: 275 Jan 21 01:11:48.967 FPS: 32 Texture Memory: 4.7mb System Memory: 11.14mb Stage Objects: 287 Jan 21 01:11:49.460 FPS: 60 Texture Memory: 4.7mb System Memory: 9.45mb Stage Objects: 289 Jan 21 01:11:49.956 FPS: 60 Texture Memory: 4.7mb System Memory: 7.73mb Stage Objects: 287 Jan 21 01:11:50.569 FPS: 55 Texture Memory: 4.58mb System Memory: 6.34mb Stage Objects: 287 Jan 21 01:11:51.124 FPS: 60 Texture Memory: 4.58mb System Memory: 11.57mb Stage Objects: 287 Jan 21 01:11:51.672 FPS: 51 Texture Memory: 4.58mb System Memory: 9.73mb Stage Objects: 287 Jan 21 01:11:52.196 FPS: 60 Texture Memory: 4.58mb System Memory: 7.86mb Stage Objects: 287 Jan 21 01:11:52.695 FPS: 56 Texture Memory: 4.58mb System Memory: 12.78mb Stage Objects: 287 Jan 21 01:11:53.238 FPS: 60 Texture Memory: 4.58mb System Memory: 12.11mb Stage Objects: 287 Jan 21 01:11:53.765 FPS: 59 Texture Memory: 4.58mb System Memory: 10.36mb Stage Objects: 287 Jan 21 01:11:54.358 FPS: 56 Texture Memory: 4.58mb System Memory: 8.51mb Stage Objects: 287 Jan 21 01:11:54.949 FPS: 23 Texture Memory: 4.58mb System Memory: 9.24mb Stage Objects: 289 Jan 21 01:11:55.478 FPS: 60 Texture Memory: 4.7mb System Memory: 13.09mb Stage Objects: 287 Jan 21 01:11:56.101 FPS: 60 Texture Memory: 4.7mb System Memory: 11.21mb Stage Objects: 289 Jan 21 01:11:56.702 FPS: 33 Texture Memory: 4.7mb System Memory: 9.24mb Stage Objects: 287 Jan 21 01:11:57.401 FPS: 38 Texture Memory: 4.7mb System Memory: 7.29mb Stage Objects: 283 Jan 21 01:11:58.061 FPS: 30 Texture Memory: 4.7mb System Memory: 14.28mb Stage Objects: 283 Jan 21 01:11:58.791 FPS: 60 Texture Memory: 4.7mb System Memory: 12.24mb Stage Objects: 287 Jan 21 01:11:59.531 FPS: 54 Texture Memory: 4.7mb System Memory: 10.21mb Stage Objects: 287 Jan 21 01:12:00.521 FPS: 38 Texture Memory: 4.7mb System Memory: 8.06mb Stage Objects: 287 Jan 21 01:12:01.368 FPS: 60 Texture Memory: 4.7mb System Memory: 15.53mb Stage Objects: 287 Jan 21 01:12:02.185 FPS: 60 Texture Memory: 4.7mb System Memory: 13.5mb Stage Objects: 287 Jan 21 01:12:03.043 FPS: 28 Texture Memory: 4.7mb System Memory: 11.43mb Stage Objects: 289 Jan 21 01:12:03.865 FPS: 57 Texture Memory: 4.7mb System Memory: 9.27mb Stage Objects: 287 Jan 21 01:12:04.734 FPS: 30 Texture Memory: 4.7mb System Memory: 16.94mb Stage Objects: 287 Jan 21 01:12:05.723 FPS: 34 Texture Memory: 4.7mb System Memory: 14.63mb Stage Objects: 287
Towards the end as you can see there are brief moments where the FPS drops to about half.
I am not sure why it says there are 287 Stage Objects, because there are only 60 asteroids, one player with a health bar and two thrusters, two buttons, and a radar system with blips for some of the asteroids. This should only account for about half of the # of stage objects that is being printed out.
I’m not sure about this, but based on the name (current stage is the top group that owns all other groups and objects) I’m assuming stage objects are any display object (not physics bodies) that have been created and still exist somewhere.
This is ALL display objects that have been created till that point and not deleted, regardless of whether you are showing them in the visible area of the screen or not.
One way you could have MORE stage objects than you think should be counted:
create a scene with objects
change scenes to a new scene and create more objects w/o destroying last scene
I think your removal code is not working as expected. Furthermore, if those objects all have bodies… then they are slowing down your game.
I am not switching between scenes, there is currently only one scene so far in this game. However, one thing I did notice was that when I moved the max limit for asteroids from 60 to 59 as a test, the number of stage objects went down by 4, from 287 to 283.
I am not sure why, though. This means that the asteroids account for 240 of the display objects.
I will put together a test to see if the code is actually removing the asteroids.
That tells me, for every asteroid you think you’re making you’re making 4. So I think you’ve got a code bug.
I’m curious what your test will be as you may run into issues. By the fact that you’re trying to measure the state of the system you are affecting it. Specifically you need a way to count objects. Counting them requires a reference. Having a reference keeps them from garbage collecting.
You may very well need a mentor/experienced coder to look at your code for you if you stay stuck.
I can’t speak to the frame-rate-drop issue, but I believe a bug in Visual Monitor is what’s causing a too-high object count to be reported.
See below for fix:
local function deepNumChildren(group) local function countChildren(agroup) local count = 0 \<== 'count' was originally being initialized to '1' if agroup.numChildren and not agroup.isMonitor then count = count + agroup.numChildren for i = agroup.numChildren, 1, -1 do count = count + countChildren(agroup[i]) end end return count end return countChildren(group) end
Btw, ‘deepNumChildren’ is a function within the VisualMonitor source code.
After initializing ‘count’ to ‘0’ instead of ‘1’, it began working as expected (i.e. When I create one display object, the object count reported increases by only one).
I checked the code on the monitor and it is not very accurate/useful for FPS monitoring.
A much better solution is to time each frame and return an average of those rather than what it is doing which is returning a snapshot frame rate based on the current frame every <game fps>/10.
local function countAllDisplayObjects(group) local count = 0 local function countChildren(agroup) if agroup.numChildren and not agroup.isMonitor then count = count + agroup.numChildren for i = agroup.numChildren, 1, -1 do countChildren(agroup[i]) end end end countChildren(group) return count end print( countAllDisplayObjects(display.getCurrentStage()) )
Thank you. However, the problem now comes with fixing this problem.
When I remove an asteroid, the # of stage objects decreases by 2. Also I notice that the more I hit asteroids, the more the System Memory value increases, and the more the FPS drops.
Do you use a finalize event listener on your asteroids? If you don’t… you should.
local asteroid = … your code to make an asteroid asteroids[asteroid] = asteroid – put it in a tracking table. function asteroid.finalize( self ) asteroids[self] = nil – stop tracking in ‘asteroids’ table. end asteroid:addEventListener(“finalize”)