Skip to content

Commit

Permalink
Added FlxVisual class to consolidate functions used by visible FlxCor…
Browse files Browse the repository at this point in the history
…e objects. Added fade function to FlxVisible objects.
  • Loading branch information
unknown authored and unknown committed Jan 24, 2010
1 parent 0bcf519 commit 48c6811
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 374 deletions.
Binary file added docs/images/Thumbs.db
Binary file not shown.
101 changes: 6 additions & 95 deletions org/flixel/FlxBlock.as
Expand Up @@ -9,7 +9,7 @@ package org.flixel
* This is the basic "environment object" class, used to create simple walls and floors.
* It can be filled with a random selection of tiles to quickly add detail.
*/
public class FlxBlock extends FlxCore
public class FlxBlock extends FlxVisual
{
/**
* Array of rectangles used to quickly blit the tiles to the screen.
Expand All @@ -28,11 +28,6 @@ package org.flixel
protected var _p:Point;
protected var _pixels:BitmapData;
protected var _framePixels:BitmapData;
protected var _alpha:Number;
protected var _alphaGlobal:Number;
protected var _color:uint;
protected var _colorGlobal:uint;
protected var _ct:ColorTransform;
//protected var _mtx:Matrix;


Expand All @@ -52,9 +47,6 @@ package org.flixel
width = _bw = Width;
height = _bh = Height;
fixed = true;

_alpha = _alphaGlobal = 1;
_color = _colorGlobal = 0xffffffff;
}

/**
Expand Down Expand Up @@ -93,7 +85,9 @@ package org.flixel
*/
override public function render():void
{
super.render();
if(!visible || _alpha == 0)
return;

getScreenXY(_p);
var opx:int = _p.x;
var rl:uint = _rects.length;
Expand All @@ -109,92 +103,9 @@ package org.flixel
}
}

/**
* Set <code>alpha</code> to a number between 0 and 1 to change the opacity of the block.
*/
override public function get alpha():Number
{
return _alpha;
}

/**
* @private
*/
override public function set alpha(Alpha:Number):void
{
if(Alpha > 1) Alpha = 1;
if(Alpha < 0) Alpha = 0;
if(Alpha == _alpha) return;
_alpha = Alpha;
setColorTransform();
}

/**
* @private
*/
override public function get alphaGlobal():Number
{
return _alphaGlobal;
}

/**
* @private
*/
override public function set alphaGlobal(Alpha:Number):void
{
if(Alpha > 1) Alpha = 1;
if(Alpha < 0) Alpha = 0;
if(Alpha == _alphaGlobal) return;
_alphaGlobal = Alpha;
setColorTransform();
}

/**
* Set <code>color</code> to a number in this format: 0xRRGGBB.
* <code>color</code> IGNORES ALPHA. To change the opacity use <code>alpha</code>.
* Tints the whole block to be this color (similar to OpenGL vertex colors).
*/
override public function get color():uint
{
return _color;
}

/**
* @private
*/
override public function set color(Color:uint):void
{
Color &= 0x00ffffff;
if(_color == Color) return;
_color = Color;
setColorTransform();
}

/**
* @private
*/
override public function get colorGlobal():uint
{
return _colorGlobal;
}

/**
* @private
*/
override public function set colorGlobal(Color:uint):void
{
Color &= 0x00ffffff;
if(_color == Color) return;
_colorGlobal = Color;
setColorTransform();
}

private function setColorTransform():void
override internal function setColorTransform():void
{
var a = _alpha*_alphaGlobal;
var c = _color&_colorGlobal;
if((a != 1) || (c != 0x00ffffff)) _ct = new ColorTransform(Number(c>>16)/255,Number(c>>8&0xff)/255,Number(c&0xff)/255,a);
else _ct = null;
super.setColorTransform();
calcFrame();
}

Expand Down
2 changes: 1 addition & 1 deletion org/flixel/FlxG.as
Expand Up @@ -33,7 +33,7 @@ package org.flixel
* Assign a minor version to your library.
* Appears after the decimal in the console.
*/
static public var LIBRARY_MINOR_VERSION:uint = 54;
static public var LIBRARY_MINOR_VERSION:Number = 54.2;

/**
* Internal tracker for game pause state.
Expand Down
95 changes: 4 additions & 91 deletions org/flixel/FlxLayer.as
Expand Up @@ -3,26 +3,19 @@ package org.flixel
/**
* This is an organizational class that can update and render a bunch of FlxCore objects
*/
public class FlxLayer extends FlxCore
public class FlxLayer extends FlxVisual
{
/**
* Array of all the FlxCore objects that exist in this layer.
*/
protected var _children:Array;

//Various rendering helpers
protected var _alpha:Number;
protected var _alphaGlobal:Number;
protected var _color:uint;
protected var _colorGlobal:uint;

/**
* Constructor
*/
virtual public function FlxLayer()
{
_alpha = _alphaGlobal= 1;
_color = _colorGlobal = 0x00ffffff;
super();
_children = new Array();
}

Expand Down Expand Up @@ -79,87 +72,7 @@ package org.flixel
}
}

/**
* Set <code>alpha</code> to a number between 0 and 1 to change the opacity of the sprite.
*/
override public function get alpha():Number
{
return _alpha;
}

/**
* @private
*/
override public function set alpha(Alpha:Number):void
{
if(Alpha > 1) Alpha = 1;
if(Alpha < 0) Alpha = 0;
if(Alpha == _alpha) return;
_alpha = Alpha;
setColorTransform();
}

/**
* @private
*/
override public function get alphaGlobal():Number
{
return _alphaGlobal;
}

/**
* @private
*/
override public function set alphaGlobal(Alpha:Number):void
{
if(Alpha > 1) Alpha = 1;
if(Alpha < 0) Alpha = 0;
if(Alpha == _alphaGlobal) return;
_alphaGlobal = Alpha;
setColorTransform();
}

/**
* Set <code>color</code> to a number in this format: 0xRRGGBB.
* <code>color</code> IGNORES ALPHA. To change the opacity use <code>alpha</code>.
* Tints the whole sprite to be this color (similar to OpenGL vertex colors).
*/
override public function get color():uint
{
return _color;
}

/**
* @private
*/
override public function set color(Color:uint):void
{
Color &= 0x00ffffff;
if(_color == Color) return;
_color = Color;
setColorTransform();
}

/**
* @private
*/
override public function get colorGlobal():uint
{
return _colorGlobal;
}

/**
* @private
*/
override public function set colorGlobal(Color:uint):void
{
Color &= 0x00ffffff;
if(_color == Color) return;
_colorGlobal = Color;
setColorTransform();
}

internal function setColorTransform():void
override internal function setColorTransform():void
{
var a = _alpha*_alphaGlobal;
var clr = _color&_colorGlobal;
Expand All @@ -181,7 +94,7 @@ package org.flixel
*/
override public function render():void
{
if(!visible)
if(!visible || _alpha == 0)
return;

var c:FlxCore;
Expand Down

0 comments on commit 48c6811

Please sign in to comment.