Graphics File Size Optimization


  • Posts: 14
Ok, so I'm trying to trim down the size of my game's SWF. I have a number of scrolling backgrounds that are meant to be out-of-focus silhouettes with things behind them, so I originally brought them into Stencyl as PNG-24s, since I need the transparency to have soft edges. These worked nicely.

Thinking they were probably having a negative effect on my file size, though, I came up with an idea - I could replace them with grayscale JPEGs that would serve as the alpha channels, and then work a little magic with them at runtime to generate the colored silhouettes. The JPEGs are 10-12 times smaller than the PNGs, so I figured I'd realize a significant savings.

Before digging into the code, though, I did a quick test. I published two SWFs - one using the PNGs and one using the grayscale JPEGs. To my bafflement, the one with the JPEGs ended up being a slightly *larger* file than the one with the PNGs.

So my question here is this: does the file size of the source images not matter once they're imported into Stencyl? Is it just the raw number of pixels that determines how much heft a particular graphic adds to the SWF? Or am I possibly missing something somewhere? If it isn't obvious, I'm somewhat new to this, so any advice on optimizing my graphics for file size is welcome.

Thanks in advance!


  • *
  • Posts: 9472
The file size does matter, and you should always use PNG for Flash, not JPEG.


  • Posts: 591
I wonder, maybe try importing the PNGs with dimensions halved (so they're actually smaller), and try resizing them in the game? O.o'

I don't know whether the result will be favorable or not, but I suppose it's worth trying. ^^'

Oh, and for resizing; once you have an actor in game with a single-frame animation called "Animation", you can use such code in Drawing event:
g.drawImage(actor.anims["Animation"].pixels, actor.x, actor.y, [width], [height]);
with [width] and [height] replaced with the original dimensions. far as I remember, at least. O.o'
(and if you do so, don't forget to hide actor in Created event with a block in Actor >> Drawing palette!)