Advertisement
Guest User

PreRotation Demo - TestThing.as

a guest
Sep 29th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.BitmapData;
  3.     import flash.display.Graphics;
  4.     import flash.display.Sprite;
  5.     import flash.geom.Rectangle;
  6.     import net.flashpunk.Entity;
  7.     import net.flashpunk.FP;
  8.     import net.flashpunk.graphics.Image;
  9.     import net.flashpunk.graphics.PreRotation;
  10.     import net.flashpunk.graphics.Stamp;
  11.     /**
  12.      * ...
  13.      * @author NotARaptor
  14.      */
  15.     public class TestThing extends Entity {
  16.        
  17.         public static const HANDLE_CENTRE:uint = 0;
  18.         public static const HANDLE_BASE:uint = 1;
  19.         public static const HANDLE_TIP:uint = 2;
  20.         public static const HANDLE_TOPLEFT:uint = 3;
  21.         public static const HANDLE_BOTTOMLEFT:uint = 4;
  22.        
  23.         private static var _bmp1:BitmapData = null;
  24.         private static var _bmp2:BitmapData = null;
  25.        
  26.         private var gfx1:PreRotation;
  27.         private var gfx2:PreRotation;
  28.        
  29.         public function TestThing(x:Number = 0, y:Number = 0) {
  30.             super(x, y);
  31.             if (!_bmp1) _createBitmap();
  32.            
  33.             gfx1 = new PreRotation(_bmp1, 36, true);
  34.             gfx2 = new PreRotation(_bmp2, 36, true);
  35.            
  36.             addGraphic(gfx1);
  37.             addGraphic(gfx2);
  38.            
  39.             gfx2.visible = false;
  40.            
  41.             setHandle(HANDLE_BASE);
  42.         }
  43.        
  44.         public function setHandle(where:uint):void {
  45.             switch (where) {
  46.                 case HANDLE_CENTRE:
  47.                     gfx1.centerOrigin();
  48.                     gfx2.centerOrigin();
  49.                     break;
  50.                 case HANDLE_BASE:
  51.                     gfx1.originX = 30; gfx1.originY = 30;
  52.                     gfx2.originX = 30; gfx2.originY = 30;
  53.                     break;
  54.                 case HANDLE_TIP:
  55.                     gfx1.originX = 200; gfx1.originY = 30;
  56.                     gfx2.originX = 200; gfx2.originY = 30;
  57.                     break;
  58.                 case HANDLE_TOPLEFT:
  59.                     gfx1.originX = 0; gfx1.originY = 0;
  60.                     gfx2.originX = 0; gfx2.originY = 0;
  61.                     break;
  62.                 case HANDLE_BOTTOMLEFT:
  63.                     gfx1.originX = 0; gfx1.originY = 60;
  64.                     gfx2.originX = 0; gfx2.originY = 60;
  65.                     break;
  66.             }
  67.         }
  68.        
  69.         public function toggleBackground():void {
  70.             if (gfx1.visible) {
  71.                 gfx1.visible = false;
  72.                 gfx2.visible = true;
  73.             }
  74.             else {
  75.                 gfx2.visible = false;
  76.                 gfx1.visible = true;
  77.             }
  78.         }
  79.        
  80.         private static function _createBitmap():void {
  81.             _bmp1 = new BitmapData(200, 60, true, 0);
  82.             _bmp2 = new BitmapData(200, 60, false, 0xFFFFFF);
  83.             var s:Sprite = FP.sprite, g:Graphics = s.graphics;
  84.            
  85.             g.clear();
  86.             g.beginFill(0x0033FF);
  87.             g.moveTo(30, 0);
  88.             g.lineTo(200, 30);
  89.             g.lineTo(30, 60);
  90.             g.endFill();
  91.             g.beginFill(0x0033FF);
  92.             g.drawCircle(30, 30, 30);
  93.             g.endFill();
  94.  
  95.             _bmp1.draw(s);
  96.             _bmp2.draw(s);
  97.            
  98.         }
  99.        
  100.         override public function update():void {
  101.             gfx1.frameAngle += FP.elapsed * 360;
  102.             gfx2.frameAngle += FP.elapsed * 360;
  103.         }
  104.        
  105.         override public function render():void {
  106.             super.render();
  107.            
  108.             var r:Rectangle = FP.rect;
  109.             r.left = x; r.width = 1;
  110.             r.top = 0; r.height = FP.height;
  111.             FP.buffer.fillRect(r, 0xFF0000);
  112.             r.left = 0; r.width = FP.width;
  113.             r.top = y; r.height = 1;
  114.             FP.buffer.fillRect(r, 0xFF0000);
  115.         }
  116.        
  117.     }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement