Packagenet.kawa.display
Classpublic class KDrawSprite
InheritanceKDrawSprite Inheritance flash.display.Sprite

Draw the source DisplayObject as a bitmap image to get better GPU performance.

View the examples



Public Methods
 MethodDefined By
  
KDrawSprite(autoDispose:Boolean = true)
Creates a new KDrawSprite instance.
KDrawSprite
  
dispose():void
Frees memory of the internal bitmap image.
KDrawSprite
  
draw(source:DisplayObject, quality:Number = 1):void
Draws the source DisplayObject onto the internal bitmap image.
KDrawSprite
  
getBitmapData(source:DisplayObject, quality:Number = 1):BitmapData
[static] Draws the source DisplayObject as a bitmap image.
KDrawSprite
  
getSprite(source:DisplayObject, quality:Number = 1):Sprite
[static] Draws the source DisplayObject as a bitmap image.
KDrawSprite
Constructor Detail
KDrawSprite()Constructor
public function KDrawSprite(autoDispose:Boolean = true)

Creates a new KDrawSprite instance.

Parameters
autoDispose:Boolean (default = true) — Specifies whether internal BitmapData will be disposed by KDrawSprite when removed from Stage.
Method Detail
dispose()method
public function dispose():void

Frees memory of the internal bitmap image. Call this when autoDispose is false.

draw()method 
public function draw(source:DisplayObject, quality:Number = 1):void

Draws the source DisplayObject onto the internal bitmap image.

Parameters

source:DisplayObject — Source DisplayObject to draw. Ex. Sprite, Shape, etc.
 
quality:Number (default = 1) — Rendering quality. The default is 1 (NoAA). 2 means 2x SSAA, super sampling anti-aliasing.


Example
         var view:KDrawSprite = new KDrawSprite();
         addChild(view);
         
         var work:Sprite = new Sprite();
         work.graphics.beginFill(0xFFCC99);
         work.graphics.drawRect(0, 0, 100, 100);
         view.draw(work);
         
getBitmapData()method 
public static function getBitmapData(source:DisplayObject, quality:Number = 1):BitmapData

Draws the source DisplayObject as a bitmap image. Returns it as a BitmapData object.

Parameters

source:DisplayObject — Source DisplayObject to draw. Ex. Sprite, Shape, etc.
 
quality:Number (default = 1) — Rendering quality. The default is 1 (NoAA). 2 means 2x SSAA, super sampling anti-aliasing.

Returns
BitmapData — A BitmapData object rendered.

Example
         var bitmap:Bitmap = new Bitmap();
         addChild(bitmap);
         
         var shape:Shape = new Shape();
         shape.graphics.beginFill(0xFFCC99);
         shape.graphics.drawRect(0, 0, 100, 100);
         bitmap.bitmapData = KDrawSprite.getBitmapData(shape);
         
getSprite()method 
public static function getSprite(source:DisplayObject, quality:Number = 1):Sprite

Draws the source DisplayObject as a bitmap image. Returns it as a Sprite object.

Parameters

source:DisplayObject — Source DisplayObject to draw. Ex. Sprite, Shape, etc.
 
quality:Number (default = 1) — Rendering quality. The default is 1 (NoAA). 2 means 2x SSAA, super sampling anti-aliasing.

Returns
Sprite — A Sprite object which has a Bitmap image rendered.

Example
         var sprite:Sprite = new Sprite();
         sprite.graphics.beginFill(0x336699);
         sprite.graphics.drawCircle(50, 50, 50);
         sprite = KDrawSprite.getSprite(sprite);
         addChild(sprite);
         
Examples
Call KDrawSprite.getSprite() instead of setting cacheAsBitmapMatrix and cacheAsBitmap properties.
     var sprite:Sprite = new Sprite();
     sprite.graphics.beginFill(0x336699);
     sprite.graphics.drawCircle(50, 50, 50);
     
     // sprite.cacheAsBitmapMatrix = new Matrix(); // BEFORE
     // sprite.cacheAsBitmap = true;
     
     sprite = KDrawSprite.getSprite(sprite);       // AFTER
     
     addChild(sprite);
     sprite.x = 100;
     sprite.y = 100;
     sprite.scaleX = 0.5;
     sprite.height = 50;
     sprite.rotation = 1;