Author Topic: Stardust particle engine not working with Flixel !!!  (Read 3227 times)

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
It's "working", but not good...
1) at some times particles stop emitting and then they emit again
2) sometimes particles stay on the screen
3) game ALWAYS freezes after some time.. Amount of time is each time different and it seems that it happens in random situations...
Stuff is that game doesn't freeze completely only display does.. Sound is still playing =)
After some time i get timeout error and it always says something different, there is error in different line of Stardust ...
I am sure this is because i am adding render to FlxState.. Stardust's render accepts Sprite object on which he then draws i guess particles.. So i gave him current FlxState..
I already shown this to creator of Stardust and he checked my code..
I done everything good!!! There is no mistakes in my code for sure!
Here i have 1 example project i made that simulates the error.. 
http://rapidshare.com/files/338917686/TESTX.rar.html
Game freezes and everything the same like my original game does.. 
So please check it out, there most be some conflict between FlxState and Stardust..

Thanks in advance!

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Stardust particle engine not working with Flixel !!!
« Reply #1 on: Fri, Jan 22, 2010 »
You are using the Stardust DisplayObjectRenderer, which probably isn't the best choice for this as although FlxState extends Sprite, it isn't really a true "sprite" as everything is still rendered to FlxG.buffer (a BitmapData). You should try looking at the Stardust Bitmap renderer, and giving it the FlxState.screen to draw to.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
Re: Stardust particle engine not working with Flixel !!!
« Reply #2 on: Fri, Jan 22, 2010 »
I tried FlxState.screen and its not working because that's FlxSprite and Stardust needs Sprite
« Last Edit: Fri, Jan 22, 2010 by xraven13 »

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Stardust particle engine not working with Flixel !!!
« Reply #3 on: Fri, Jan 22, 2010 »
Hiya,

Ok I had a little play with this.

If you just want to use this for visual effects (i.e. not to actually emit FlxSprites!) then the following worked for me:

This is all inside your PlayState.as:

Add a bitmapData, your particles will be drawn here:

Code: [Select]
b = new BitmapData(640, 480, true, 0xffffff);
Create an emitter and renderer, here's the one I used:

Code: [Select]
emitter = new Emitter2D(new SteadyClock(1));
renderer = new BitmapRenderer(b);
renderer.addEmitter(emitter);

var d:DisplayObjectClass = new DisplayObjectClass(latte);
var position:Position = new Position(new Line(0, 0, 640, 0));
var velocity:Velocity = new Velocity(new SinglePoint(0, 4));

emitter.addInitializer(d);
emitter.addInitializer(position);
emitter.addInitializer(velocity);

var move:Move = new Move();
var deathZone:DeathZone = new DeathZone(new RectZone(0, 0, 640, 400), true);

emitter.addAction(move);
emitter.addAction(deathZone);

Note that it will render to the bitmapData (b) we created above. The rest is just standard stuff taken from the Stardust tutorial.

The one thing worth pointing out is the class given to the DisplayObjectClass - in this case its called "latte" which is just an embedded Bitmap with the class name set to "latte" (I was drinking one at the time!)

Ok so that's it.. back to your PlayState.as:

1) Call emitter.step() in your update function

.. and now just decide when to apply the particles.

You can choose to do it in 3 places.. preProcess, the update phase or postProcess. Depending on your set-up depends which is best. For example here is my preProcess with a blur effect:

Code: [Select]
override public function preProcess():void
{
b.applyFilter(b, new Rectangle(0, 0, b.width, b.height), new Point, new BlurFilter(6, 6, 1));
screen.drawFromBitmapData(b, 0, 0);
}

Now I admit I had to create the "drawFromBitmapData" method in FlxSprite, as simply updating the pixels value caused the sprite reset, which ****ed it up. So here is the method I added:

Code: [Select]
/**
* This function merges one bitmapData with the current sprite
* This function is NOT intended to replace <code>render()</code>!
*
* @param B The bitmapData you want to stamp onto this sprite.
* @param X The X coordinate of the brush's top left corner on this sprite.
* @param Y They Y coordinate of the brush's top left corner on this sprite.
*/
public function drawFromBitmapData(b:BitmapData, X:int=0, Y:int=0):void
{
_p.x = X;
_p.y = Y;
_r2.width = b.width;
_r2.height = b.height;
_pixels.copyPixels(b,_r2,_p,null,null,true);
_r2.width = _pixels.width;
_r2.height = _pixels.height;
calcFrame();
return;
}

Very simple stuff - just merges the given bitmapData (in this case your particles) with the current screen buffer.

So if you call this in preProcess it will do it before all other FlxSprites etc are added. If you call it during postProcess it sticks them on-top of the screen. I don't know where it'll work best for you.

So ok not quite that straight forward - but ultimately it works ok :)

Cheers,

Rich
« Last Edit: Fri, Jan 22, 2010 by photonstorm »
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Stardust particle engine not working with Flixel !!!
« Reply #4 on: Fri, Jan 22, 2010 »
Oh it's also worth pointing out that I didn't look at using a Layer instead - this should be a more elegant solution to using pre/post updates.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
Re: Stardust particle engine not working with Flixel !!!
« Reply #5 on: Fri, Jan 22, 2010 »
Wow great dude, thanks a lot!!! :)

fefranca

  • Guest
Re: Stardust particle engine not working with Flixel !!!
« Reply #6 on: Fri, Jan 22, 2010 »
Hi Richard, welcome to the forums!

Great to see you around here, I really like your work and blog.

Oh, and I'd love to see some PixelBlitz features in Flixel :)

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Stardust particle engine not working with Flixel !!!
« Reply #7 on: Fri, Jan 22, 2010 »
Hiya - thanks for the welcome :) without wanting to hijack this thread I just wanted to say how impressed I am with Flixel 2.0 - it has come on a long way! Really excited to be working with it.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius