HaxeFlixel/flixel — pull request #571 by skrivener (2013-08-06 02:25:07+00:00)
Title: Preliminary implementation adding bitmap blend fx to FlxCamera

For issue [552](https://github.com/HaxeFlixel/flixel/issues/552). Not a final product! ;) Looking for thoughts and feedback, test project (MenuState below) from template drops to about 55fps for me with blend enabled, bitmap size of screen, 1920 x 1080, only tested on Flash so far. Still extremely rough (as will be obvious) mostly wondering if anyone sees any further opportunity for optimization.

--- MenuState.hx

package;

import flash.display.BitmapData;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.util.FlxColor;
import flixel.system.input.keyboard.FlxKey;

/**
* A FlxState which can be used for the game's menu.
*/
class MenuState extends FlxState
{
/**
* Function that is called up when to state is created to set it up.
*/
override public function create():Void
{
// Set a background color
//FlxG.cameras.bgColor = 0xff131c1b;
FlxG.cameras.bgColor = 0xff000000;
// Show the mouse (in case it hasn't been disabled)
#if !FLX_NO_MOUSE
FlxG.mouse.show();
#end

super.create();

var mySprite1:FlxSprite = new FlxSprite();
mySprite1.makeGraphic(100, 100, FlxColor.CORAL);
mySprite1.x = mySprite1.y = 1;
mySprite1.drawDebug();
add(mySprite1);

var mySprite2:FlxSprite = new FlxSprite();
mySprite2.makeGraphic(100, 100, FlxColor.IVORY);
mySprite2.x = 500;
mySprite2.y = 150;
mySprite2.drawDebug();
add(mySprite2);

var mySprite3:FlxSprite = new FlxSprite();
mySprite3.makeGraphic(100, 100, FlxColor.LIME);
mySprite3.x = 800;
mySprite3.y = 300;
add(mySprite3);
}// 1920 x 1080

/**
* Function that is called when this state is destroyed - you might want to
* consider setting all objects this state uses to null to help garbage collection.
*/
override public function destroy():Void
{
super.destroy();
}

/**
* Function that is called once every frame.
*/
override public function update():Void
{
super.update();

// toggle blend mode off/multiply
if ( FlxG.keys.justPressed("A") ) {
if ( FlxG.camera.fxCustomBlendMode == 0 ) {
var blendBmp:BitmapData = new BitmapData( FlxG.camera.width, FlxG.camera.height, true, FlxColor.AZURE );
FlxG.camera.blend(blendBmp, 1);
} else {
FlxG.camera.stopBlend();
}
//FlxG.log.add( "Toggled blend to: " + FlxG.camera._fxCustomBlend );
}
}

}