Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.BitmapData;
- import flash.display.Graphics;
- import flash.display.Sprite;
- import flash.geom.Rectangle;
- import net.flashpunk.Entity;
- import net.flashpunk.FP;
- import net.flashpunk.graphics.Image;
- import net.flashpunk.graphics.PreRotation;
- import net.flashpunk.graphics.Stamp;
- /**
- * ...
- * @author NotARaptor
- */
- public class TestThing extends Entity {
- public static const HANDLE_CENTRE:uint = 0;
- public static const HANDLE_BASE:uint = 1;
- public static const HANDLE_TIP:uint = 2;
- public static const HANDLE_TOPLEFT:uint = 3;
- public static const HANDLE_BOTTOMLEFT:uint = 4;
- private static var _bmp1:BitmapData = null;
- private static var _bmp2:BitmapData = null;
- private var gfx1:PreRotation;
- private var gfx2:PreRotation;
- public function TestThing(x:Number = 0, y:Number = 0) {
- super(x, y);
- if (!_bmp1) _createBitmap();
- gfx1 = new PreRotation(_bmp1, 36, true);
- gfx2 = new PreRotation(_bmp2, 36, true);
- addGraphic(gfx1);
- addGraphic(gfx2);
- gfx2.visible = false;
- setHandle(HANDLE_BASE);
- }
- public function setHandle(where:uint):void {
- switch (where) {
- case HANDLE_CENTRE:
- gfx1.centerOrigin();
- gfx2.centerOrigin();
- break;
- case HANDLE_BASE:
- gfx1.originX = 30; gfx1.originY = 30;
- gfx2.originX = 30; gfx2.originY = 30;
- break;
- case HANDLE_TIP:
- gfx1.originX = 200; gfx1.originY = 30;
- gfx2.originX = 200; gfx2.originY = 30;
- break;
- case HANDLE_TOPLEFT:
- gfx1.originX = 0; gfx1.originY = 0;
- gfx2.originX = 0; gfx2.originY = 0;
- break;
- case HANDLE_BOTTOMLEFT:
- gfx1.originX = 0; gfx1.originY = 60;
- gfx2.originX = 0; gfx2.originY = 60;
- break;
- }
- }
- public function toggleBackground():void {
- if (gfx1.visible) {
- gfx1.visible = false;
- gfx2.visible = true;
- }
- else {
- gfx2.visible = false;
- gfx1.visible = true;
- }
- }
- private static function _createBitmap():void {
- _bmp1 = new BitmapData(200, 60, true, 0);
- _bmp2 = new BitmapData(200, 60, false, 0xFFFFFF);
- var s:Sprite = FP.sprite, g:Graphics = s.graphics;
- g.clear();
- g.beginFill(0x0033FF);
- g.moveTo(30, 0);
- g.lineTo(200, 30);
- g.lineTo(30, 60);
- g.endFill();
- g.beginFill(0x0033FF);
- g.drawCircle(30, 30, 30);
- g.endFill();
- _bmp1.draw(s);
- _bmp2.draw(s);
- }
- override public function update():void {
- gfx1.frameAngle += FP.elapsed * 360;
- gfx2.frameAngle += FP.elapsed * 360;
- }
- override public function render():void {
- super.render();
- var r:Rectangle = FP.rect;
- r.left = x; r.width = 1;
- r.top = 0; r.height = FP.height;
- FP.buffer.fillRect(r, 0xFF0000);
- r.left = 0; r.width = FP.width;
- r.top = y; r.height = 1;
- FP.buffer.fillRect(r, 0xFF0000);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement