Hey everyone !
I am optimizing my game and I believe I found some problems in HaxeFlixel. I wanted to ask about this so that I see what was the reasons that it was done this way because maybe this stuff is really needed, but because I am not expert in HaxeFlixel structure, I don't see it.
1) In FlxSprite constructor makeGraphics is always called, and in most cases user will call makeGraphic or loadGraphic again. Situation with FlxText is not better because makeGraphic is also called in constructor of FlxText which results in 2 times calling makeGraphics even though this is called 3rd time when actual text is set.
2) Why all sprites have AnimationController even if the sprite doesn't have animations ?
3) Why is caching set as mandatory ? Set and get cache key etc is called every time pixels are changed, and this is not needed, for example in case when someone wants to directly manipulate pixels BitmapData, like in my case where I was calling pixels = new BitmapData(...). Not sure is this error with caching because every time get cache was called even though it didn't have any result, and it made also game slower every time this happened because CachedGraphics wasnt' properely destroyed ( cause I was setting pixels with pixels = new BitmapData( ... ) ...
I fixed above 3, and so far I didn't encounter any bugs, and game is running faster.
4) Is there any way to avoid updateFrameData() ? It is slow, and I am not sure is it even needed since I have simple sprite, I don't have texture or sprite sheet... I want to set pixels with new BitmapData( ... ) so my question is could this be done in simpler way ?
- for 1) to 4) :
Testing with Adobe Scout in some frames I had 12000+ allocations when
objects was created which made the game lag a lot. I also encountered
on some other places that stuff is called just so that there is no bugs,
I believe this could be fixed in some other ways with checking is
something null, and changing actions depending is it or is not...
5) When I use big object and I change the scale ( to lower or higher amount ) it slows the game a lot. I believe this is not problem with HaxeFlixel, but with bitmapData.draw method, so I wanted to ask for advice, what should I do about this. If scaling was animated would that be faster ?
This is the art I am using :
https://dl.dropboxusercontent.com/u/63196046/propeler.png6) I also fixed some other problems like in recycle Std.is is used which results in slower recycling, this can be fixed by having arrays of objects that contain only specific object types.
7) Also, does it seems to me or recycle doesn't really work when MaxSize is set to bigger then 0 because it doesn't take in account what type of object you want to recycle, it always recycle the next one in the array ?
8) Is it smart to have FlxSprites as variables in other FlxSprite, and then in draw method of that FlxSprite call draws of other FlxSprite that are members of it ? I am not adding those FlxSprites anywhere so their update is not called ( not sure is this okay ? ), and also their draw is called only once. Here is a screenshot of case like this :
https://dl.dropboxusercontent.com/u/63196046/draw.png Notice the big memory, and notice that the next frame it is everything okay. How is this possible ? Shouldn't drawing have constant performanse if nothing is changed ?
Thanks for reading, answers, and big thank you for awesome framework !!! I am working now on sequel of Sudden Aviator, and comparing to AS3 Flixel the game is running at least 2 times faster even though in sequel I have much more objects on the screen, and game is more complex. :)