Created
August 22, 2012 21:29
-
-
Save MattRix/3429569 to your computer and use it in GitHub Desktop.
A way of using the display tree while still only drawing bitmaps in AS3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ca.struct | |
{ | |
import flash.display.Bitmap; | |
import flash.display.BitmapData; | |
import flash.display.Sprite; | |
import flash.events.Event; | |
[SWF (width=500,height=400,backgroundColor=0x000000,frameRate=60)] | |
public class BitmapHierarchyTester extends Sprite | |
{ | |
private var _hiddenHolder:Sprite; | |
private var _screenBMD:BitmapData; | |
private var _someContainer:Sprite; | |
private var _someCircle:Sprite; | |
public function BitmapHierarchyTester() | |
{ | |
addChild(_hiddenHolder = new Sprite()); | |
_hiddenHolder.visible = false; | |
_screenBMD = new BitmapData(500,400); | |
addChild(new Bitmap(_screenBMD)); | |
setupScene(); | |
addEventListener(Event.ENTER_FRAME, onEnterFrame); | |
} | |
private function setupScene() : void | |
{ | |
_hiddenHolder.addChild(_someContainer = new Sprite()); | |
_someContainer.addChild(_someCircle = new Sprite()); | |
_someContainer.x = 100; | |
_someContainer.y = 100; | |
_someCircle.x = 50; | |
_someCircle.y = 0; | |
_someCircle.alpha = 0.5; | |
_someCircle.graphics.beginFill(0xFF0000,1.0); | |
_someCircle.graphics.drawCircle(0,0, 10); | |
_someCircle.graphics.endFill(); | |
} | |
private function onEnterFrame(event : Event) : void | |
{ | |
_someCircle.x += 0.01; | |
_someContainer.rotation += 1.0; | |
_screenBMD.fillRect(_screenBMD.rect, 0x000000); | |
_screenBMD.draw(_someCircle,_someCircle.transform.concatenatedMatrix, _someCircle.transform.concatenatedColorTransform); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment