Giter Club home page Giter Club logo

starling-ffparticlesystem's Introduction

Starling-FFParticleSystem

Improved particle system for the Starling framework

Short overview and live demo: http://www.flintfabrik.de/blog/improved-particle-system-for-starling

Getting started: Starling wiki page

Overview

This is particle system is based on and compatible to the original but provides some additional features and various performance improvements. Thanks a lot to Colin Northway (Incredipede) sponsoring this extension created for his upcoming game.

Important: I did anything to make the code as fast as possible but to get the best performance I strongly recommend using the ASC 2.0 compiler and setting it up for [inline] functions.

####New Features:

  • particle pool
  • batching (less draw calls)
  • multi buffering (avoid stalling)
  • animated particles
  • random start frames
  • filter support
  • optional custom sorting, code and variables
  • calculating bounds (optional)
  • spawnTime, fadeIn/fadeOut
  • emit angle alligned particle rotation
  • various performance improvements

Additional information about the new features and the live demo (~ 5 MB) can be found on my page.

starling-ffparticlesystem's People

Contributors

adolio avatar jarkkosyrjala avatar shin10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

starling-ffparticlesystem's Issues

Performance improvement when generating Frames?

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?

DemoStarlingMain.as Error: Call to a possibly undefined method createBuffer

@shin10
Trying to compile the Demo I get these errors with Starling 2.3:

DemoStarlingMain.as(247): col: 26 Error: Call to a possibly undefined method createBuffers.
				ffpsStyle.effectType.createBuffers(4096, 16);
				                     ^
DemoStarlingMain.as(248): col: 37 Error: Call to a possibly undefined method createBuffers.
				FFParticleStyleClone.effectType.createBuffers(4096, 16);

Any idea on a workaroud in order to compile?

start / stop methods do not behave like old particles system

Hi,

The start method has no effect if called after the disappearance of all particles following a call to stop.

This behavior is a bit annoying because sometimes user would like to have a particles system which start, stop and restart later on. Perhaps start should handle internally the resume case. It's maybe easier to have only start and stop and remove resume.

The above issue seems to come from that condition in the start method :

if (mEmissionRate != 0 && !mCompleted) { ... }

If complete, impossible to restart by just calling start.

Thanks in advance for your feedback.

Not working with Starling 2.0

Used this extesion a lot, great work!

But after upgrading to Starling 2.0 it stops compiling //
starling.core.RenderSupport and starling.utils.VertexData not found anymore.

Are there any plans to update for 2.0 compatibility? Hoping there is not much to do.

Juggler error

I'm getting these error when I call start()
Error #1009: Cannot access a property or method of a null object reference.
.......FFParticleSystem.as:1738

that's mJuggler.add(this);

I'm using the standard code to initialize

                var particleTexture:Texture = Game.assets.getTexture("particle_bullet");
        var particleConfig:XML = XML(Game.assets.getXml("particle"));
        // create system options
        var sysOpt:SystemOptions = SystemOptions.fromXML(particleConfig, particleTexture);
        FFParticleSystem.init(1024, false, 512, 4);

        ps = new FFParticleSystem(sysOpt);
        ps.emitterX = 160;
        ps.emitterY = 240;
        addChild(ps);

        ps.start();

Potential Issue?

Hey, hate to open an issue here when I'm not sure if your project is to blame, but want to make sure you see it.

http://forum.starling-framework.org/topic/filter-error

I was wondering if it was possible if there could be issues related to the particles going beyond 2048 in dimension, or something like that?

Thanks! Feel free to close this issue if it's not applicable. :)

A bug and memory leak!

I have finished experimenting with FFParticle stress tests and although the performance is amazing I had an issue tracking down a memory leak which ended in FFParticleSystem.
In my current setup I relying on "FFParticleSystem.init(1024, false, 512, 8);" and "FFParticleSystem.dispose();" (resetting the particle system with different configurations for the current scene state). During a scene lifetime I spawn particle systems ( alot of them ). When "FFParticleSystem.dispose()" is called I noticed memory not being released. The static function "dispose()" calls internally for "disposePool()" which looks like this:

public static function disposePool():void
{
for each (var instance:FFParticleSystem in sInstances)
{
instance.dispose();
}

sParticlePool = null;

}

Following down the "instance.dispose()" method leads to this:

public override function dispose():void
{
sInstances.splice(sInstances.indexOf(this), 1); // <= modifies the length
removeEventListener(starling.events.Event.ADDED_TO_STAGE, addedToStageHandler);
stop(true);
mBatched = false;
super.filter = mFilter = null;
removeFromParent();

super.dispose();
mDisposed = true;

}

You call "sInstances.splice(sInstances.indexOf(this), 1);" which modifies the vector length and messes up the previous loop "for each (var instance:FFParticleSystem in sInstances)" resulting in a number of skipped instances not getting disposed. The quick fix I did was this:

for (var i : int=sInstances.length-1; i>=0; i--)
{
sInstances[i].dispose();
}

This bug does not lead to a memory leak but it can lead to a runtime error when after calling:
FFParticleSystem.dispose(), a "skipped from being disposed" ParticleSystem may be left on stage or inside a starling sprite and if you call dispose() on that sprite container it will iterate trough all children and call dispose on them. Call will brake when a particle system is encountered.

rotation in texture atlas causes particles to be scaled incorrectly

I have a particle that is longer than it is tall. The image file itself is 64x64 but when I set Texture Packer to trim whitespace it ends up as 64x25. I've also allowed rotations in Texture Packer. The combination of these two things seems to confuse FFParticleSystem about which dimension is the height and the width. So it mistakes the 25 for the width and scales up the particles accordingly (64/25 = 256% scale).

I can work around this issue by disallowing rotation in my texture atlas

Example Particle

Error #3694: The object was disposed by an earlier call of dispose() on it.

I'm getting the following error:

Error: Error #3694
    at de.flintfabrik.starling.display::FFParticleSystem/renderCustom()
    at de.flintfabrik.starling.display::FFParticleSystem/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.display::Sprite/render()
    at starling.display::DisplayObjectContainer/render()
    at starling.core::Starling/render()
    at starling.core::Starling/nextFrame()
    at starling.core::Starling/onEnterFrame()

This can be reliably reproduced for my project when I trigger a context loss while loading my assets. To clarify, I can easily reproduce this by calling Starling.context.dispose() while AssetManager.loadQueue() is in progress (and the particle assets are part of the assets being loaded).

Any ideas for fixing this? The Event.TEXTURES_RESTORED appears to be coming back before the FFParticleSystem instances are created, so I'm not sure why it's problematic.

FFParticleSystem doesn't work with atlas rotations

If you allow rotations in TexturePacker to save space, FFParticleSystem won't adjust for the rotation and instead draws the pfx in whatever orientation is saved to the atlas. Starling has had atlas rotation support since 1.5 so FFParticleSystem should support it as well for parity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.