This looks like a good test case for the "only profile slow frames feature" (Profile slow frames only), also trying to figure out what's going on with that occasional hang (garbage collection, almost certainly), so I'm playing around with this today. Should I post bug reports here as I hit them, or would you rather have them in DM?
First thing I noticed running it under the profiler: In that laggy title screen it's spending almost all of its time calling sprite:setScale()
and sprite:setRotation()
. Those functions redraw the sprite's images immediately, which means you're doing redundant drawing if you're using them both on the same sprite. setRotation() has optional scale arguments so you can handle both scale and rotation in one go. The other thing there is it might be more efficient to skip the image backing and instead use a draw function that calls drawScaled() or drawRotated(). That will draw directly to the screen's frame buffer instead of adding an extra step of drawing to an image, and will clip off-screen drawing if the rotated image is bigger than the screen.
I'm tempted to add that as an option for image-based sprites, like a "cache transformed image" flag you'd turn off to have it do the scaling/rotating at draw time. I'll file it and think about it. Generally I'm against fiddly bits that make things more complicated, but I can see this being pretty useful.