Framerate and Memory issues


(SunShiranui) #1

Hello everyone!

I’m currently developing my first FlashPunk game, and I’m having a bit of trouble. The game works fine at first, but when I go through approximately 10-11 levels, the performance starts to drop. My FPS drop from 60 to 40-30 and my memory seems to increase with each level, using more than 300MB according to the flashpunk console.

Does anyone have any tips to avoid such problems? I’m struggling to find what I’m doing wrong. Do I need to do anything special to make sure that worlds are correctly unloaded when i change them, or does flashpunk handle that for me already?

Of course, should you need more information to help, I’ll gladly provide it. :slight_smile:


(Jacob Albano) #2

The worlds should be released by Flash’s garbage collector after you set FP.world to a new one. Are you holding a reference to the previous worlds anywhere?


(SunShiranui) #3

That’s what I thought as well. I don’t think I have any reference that could keep the worlds from being collected, but I might be wrong.

I was wondering whether using static variables in the worlds could cause this problem - for example, I have my player instance set as a public static variable, so that other classes can access things like the player position more easily using the dot notation. Only entities in the world refer to it, though. Could that still be a problem?


(Jason Pickering) #4

are you doing any recycling? and are you recycling entities after they have been used? what does your entity count look like?


(SunShiranui) #5

I’m not doing any recycling unfortunately, as I don’t know how to. I think that might explain some of my framerate drops - earlier levels have about three hundred entities, while later levels can reach up to 800. My game has some particle effects that I think I’m doing very inefficiently - each particle is an entity - and that might be what affects my framerate. I wasn’t aware of the Particle class in FlashPunk when I started coding the particles. Should I look into them? Do you recommend decreasing my entity count, and do you have any tips on recycling?

Thank you very much. :slight_smile:


(Jason Pickering) #6

yes I would try and keep your entity count really low. 800 is way to much. Also is that 800 on screen at once? can you turn off whatever is creating all those entities and see how your frame rate is. If no one else posts some code on recycling I will, I am not the best person to explain it as I dont know if I am using it in the best practice. it all depends on how you A. remove an entity, and B. Create an Entity.


(fedyfausto) #7

try to use max 80 entity :frowning:


(rostok) #8

try using http://www.sociodox.com/theminer/ this is quite a profiler. another tip is to check entities graphics, maybe you are doubling images or spritemaps with each entity’s constructor. note that only one instance of spritemap per class is needed.


(Jacob Albano) #9

Recycling will only improve performance if your bottleneck is creating entities. I would definitely recommend looking into the particle emitter class, since it soulds like that’s where your problem is.