How to process a buffered image on Neko/CPP targets?

  • I have a few FlxGroup instances with special rendering rules; such as an FlxGroup you can add shadows to to make them blur together with a decreased alpha, or an FlxGroup which will make everything fade to white. I accomplish this with the manipulation of the buffer, doing something like this:

    override public function draw():Void {
      // swap the camera buffer with an offscreen buffer
      var tmpBuffer:BitmapData =; = _whiteBuffer;
      _whiteBuffer = tmpBuffer;
      // clear the camera buffer, FlxColor.TRANSPARENT);
      // render to the camera buffer using FlxGroup.draw()
      // swap the offscreen buffer back to the camera buffer
      var tmpBuffer:BitmapData =; = _whiteBuffer;
      _whiteBuffer = tmpBuffer;
      // modify our offscreen buffer, and draw the results to the camera
      var matrix:Array<Float> = new Array<Float>();
      matrix = matrix.concat([1 - _whiteness, 0, 0, _whiteness, 0]);
      matrix = matrix.concat([0, 1 - _whiteness, 0, _whiteness, 0]);
      matrix = matrix.concat([0, 0, 1 - _whiteness, _whiteness, 0]);
      matrix = matrix.concat([0, 0, 0, 1, 0]);
      _whiteBuffer.applyFilter(_whiteBuffer, _whiteBuffer.rect, _zeroPoint, new ColorMatrixFilter(matrix));, _whiteBuffer.rect, _whiteBuffer.rect.topLeft, null, null, true);

    This approach works in Flash, but breaks in Windows. This is because Windows does not rely on blitting, so the camera buffer is not used. Is there an alternative approach which people use on Windows for custom postprocessing of an FlxGroup?

    I understand new versions of Flixel actually support PostProcessing shaders and stuff, but I'd rather just manipulate these pixels in memory with Flash filters to avoid branching code.


  • Here's what I use to blur any sprite I wish, on cpp:

    static public function blurSprite(sprite:FlxSprite,amountX:Float,amountY:Float):Void
    		var blurFilter = new BlurFilter();
    		var filterFrames = FlxFilterFrames.fromFrames(sprite.frames,*2,*2, [blurFilter]);
    		blurFilter.blurX = amountX/2;
    		blurFilter.blurY = amountY/2;
    		filterFrames.applyToSprite(sprite, false, true);

    Usage: blurSprite(spr, 0.5,0.5);

    I used to blur the background sprites with this method!

  • Thanks! I'm really hoping there's a way to apply a filter to the entire group at once, but this is still helpful.

  • @claudio-ficara how would you say this runs performance wise?

    specially for mobile

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.