shin10 / Starling-FFParticleSystem

Improved particle system for the Starling framework
42 stars 22 forks source link

Performance improvement when generating Frames? #14

Closed a13o closed 8 years ago

a13o commented 8 years ago

I noticed in FFParticleSystem.initInstance that textures that are SubTextures build their frame by referencing SubTexture.clipping multiple times.

var frame:Frame = new Frame(1, 1, st.clipping.x, st.clipping.y, st.clipping.width,
    st.clipping.height, st.rotated);

The clipping property on SubTextures must generate the clipping from scratch each time, here it is from Starling 1.8:

public function get clipping():Rectangle
{
    var topLeft:Point = new Point();
    var bottomRight:Point = new Point();

    MatrixUtil.transformCoords(mTransformationMatrix, 0.0, 0.0, topLeft);
    MatrixUtil.transformCoords(mTransformationMatrix, 1.0, 1.0, bottomRight);

     var clipping:Rectangle = new Rectangle(topLeft.x, topLeft.y,
         bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);

     RectangleUtil.normalize(clipping);
     return clipping;
 }

Would it be more performant to call clipping once into a local var and use that var when initializing frame?

shin10 commented 8 years ago

Yes, you're right. Just fixed it.

a13o commented 8 years ago

Thanks for your continued support of this awesome library!