Author Topic: Suggestion: preProcess and postProcess on FlxLayer  (Read 2472 times)

fefranca

  • Guest
It would be great to able to single out some effects to certain layers. For example, the FlxBlur method won't work if you have a nice background in your game (which would kill the effect). If each layer had its own buffer it would be a lot easier to do this.

Allow some hacking of Flixel's render functions. Maybe let FlxSprite render to an arbitrary BitmapData defined as its own private variable, not always FlxG.buffer (that could be actually nice for performance; even though you have a new instance variable there you also speed things up by not accessing a static variable on every object on every loop.)

If that is possible then whenever a FlxLayer needs a processing buffer it would just set all its children drawing buffers to its own instead of their default values (FlxG.buffer). Otherwise it could just render everything exactly like it does today.

In any case Adam and everyone, I need more coffee. Thanks for reading  ;D

sagevann

  • Guest
Re: Suggestion: preProcess and postProcess on FlxLayer
« Reply #1 on: Thu, Jan 7, 2010 »
I second this notion. 

In the game that I was making ( which I may post soon ) I had several instances where I wanted to effect individual layers with various effects ( scale, blur, move, etc ).  In the end it wasn't 100% necessary so I abandoned writing functionality to do it, but it sure would be helpful if we could get individual buffers as an option.  Being able to scale, blur, move, and apply wicked sweet convolution or other filters on a per layer basis would be a great help.

-Sage

PaulGene

  • Member
  • **
  • Posts: 83
  • Karma: +0/-0
    • View Profile
    • PaulGenehompson
Re: Suggestion: preProcess and postProcess on FlxLayer
« Reply #2 on: Thu, Jan 7, 2010 »
m00

You can already do this quite easily, just create a new class that extends FlxLayer, override the render function, point FlxG.buffer at your own buffer before you call super.render() then copy your buffer back onto FlxG.Buffer.

I gave an example that does almost the same thing here http://flixel.org/forums/index.php?topic=628.45

The only problem with all this is it will impact in your fps.

fefranca

  • Guest
Re: Suggestion: preProcess and postProcess on FlxLayer
« Reply #3 on: Thu, Jan 7, 2010 »
You are completely right Paul.. thanks a lot!

I might just add that to FlxUtils, I also wanted to make some prefab effects you could plug into a FlxLayer.

darthlupi

  • Active Member
  • ***
  • Posts: 241
  • Karma: +0/-0
  • All Smiles
    • View Profile
    • LupiGames.com
Re: Suggestion: preProcess and postProcess on FlxLayer
« Reply #4 on: Fri, Jan 8, 2010 »
Something fun I have been doing with PaulGene's example is use the new draw method, for Flxsprites, to draw the current frame of animation to the new buffer VS adding a FlxSprite directly to the layer.

This gives you the ability to have an effects layer that you draw a sprite to on the fly if predetermined events happen.
To take care of that not so fresh feeling: #flixel on irc.freenode.net.

Use your favorite IRC client or  http://webchat.freenode.net/

fefranca

  • Guest
Re: Suggestion: preProcess and postProcess on FlxLayer
« Reply #5 on: Fri, Jan 8, 2010 »
Exactly darth, doing that saves some processing time too.

Just wanted to note something I've seen in the past: a very simple way to improve the performance of Flash bitmap filters is to use a scaled down version of the bitmap to apply filters on, then write that back into the main buffer scaled up (matrices ftw).

By the way, is anyone aware of any interesting Alchemy filters we could use on Flixel projects?