Dynamic Sprite Performance Issues

Started by SilverSpook, Mon 14/12/2015 20:47:19

Previous topic - Next topic

SilverSpook

I'm considering using more dynamic sprites in my game but I'm worried it could cause problematic slowdowns in game if a lot of big dynamic sprites are generated mid-game.  On the other end, I have a lot of fairly large objects (300 - 400 pixels) that need to move around and rotate, and so if I make a lot of individual PNGs for the different rotations it seems it will take up a lot of space.

Does anyone have any experience and/or recommendations here?  Would it be better/faster performance-wise to have a single image and make a bunch of dynamic sprites for the rotations or just make separate PNGs and import for each rotation?  Thanks!

Monsieur OUXX

My piece of advice: Always apply scaling and rotation on the smallest possible sprites. That means: if your sprite gets cropped at some stage (for example: cropped by the viewport), then cropped it first and then transform it.

I didn't understand who you could use "several sprites" to replace "one large sprite" and expect to gain performance at rotation time.
 

Snarky

The "several sprites" are various pre-rotated versions of the sprite, in order to avoid run-time rotations.

Yes, that will probably be faster (possibly depending on how the sprites are loaded), but also yes, of course it will take up an order of magnitude more space. It also depends on the kind of animation you're going to use them for. If the rotation is going to be smooth and relatively slow, you'll be surprised at how small the angle increments need to be: certainly no more than a couple of degrees. And I don't suppose you want to import 40+ copies (assuming you use flipping to extend the rotation beyond 90 degrees) of every sprite.

I'd just try it the simple way (run-time rotations) and see if it causes any problems.

Quote from: Monsieur OUXX on Tue 15/12/2015 09:40:48
My piece of advice: Always apply scaling and rotation on the smallest possible sprites. That means: if your sprite gets cropped at some stage (for example: cropped by the viewport), then cropped it first and then transform it.

That sounds... impractical. How are you supposed to know which part of the sprite to crop before you've rotated it? And how do you position it correctly when you've cropped it before rotating?

Monsieur OUXX

Yes, I would recommend pre-storing rotated version of the sprite instead of rotating all of them in real-time (provided you don't expect too many fixed rendering angles). We don't know your game but if they're sprites they can't be too large and there can't be too many of them, is there?
Also, I'd suggest generating them during game loading rather than importing them -- it all depends if it doesn't bother you to have a larger game file. But for a simple processing like rotating, it will surely make your life easier to manage just one sprite than to have to re-import as many sprites as there are angles each time you change something. Simply make sure that the pre-loading will not freeze the game at the wrong time (add a load bar or whatever).

@Snarky: I don't know how large are his sprites, I was just giving general ideas.
 

SMF spam blocked by CleanTalk