FlxSprite and drawing performance

  • Hi!

    I'm working on a game that is entirely drawn by circles and lines.
    I'm having mobile performance problems, and so I would be happy for help in deciding which approach is better.

    I can either:

    1. Create one big FlxSprite, clear it at the beginning of update() (using FlxSpriteUtil.fill) and then redraw all elemnts by FlxSpriteUtils.drawLine and FlxSpriteUtils.drawCircle each frame.
    2. Create small FlxSprites that are sized by the element that's drawn on them (for example, a circle) and redraw them only when needed (i.e. when there's an animation, etc...).

    From these two approaches, which will give a better performance on mobile?
    Note: performance on desktop is great.


  • i'm pretty sure using things like drawLine() is fairly expensive

    for my game instead of using a line i use a 1x1 pixel sprite and i rotate and scale it as needed. that's also not the cheapest thing you can do but gave me much better results on mobile

  • Thanks!
    That will work for a line, however I have many circles also... and as I want a good fit for all screen sizes, will be harder to make sprites out of these circles. Also some are dynamic and grow (like waves) which using scale will just not look good...

    So basically you say that using a big FlxSprite and drawing on it won't change much? Or actually the opposite, it will be worse, as the draw function itself is what's so time consuming? I assume particularly drawCircle with sin, cos etc... Any way to speed up these drawing functions?...

  • This post is deleted!

  • @idankimel wouldn't know for sure, maybe someone else will reply with better information, but you can also benchmark it by just drawing a ton of circles with both methods and test it out. i'm sure you can get that done fairly quick

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.