Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 17th, 2012  |  syntax: None  |  size: 2.92 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package {
  2.        
  3. //AS3 VCAM!!
  4.  
  5.         import flash.display.*;
  6.         import flash.events.*;
  7.         import flash.geom.*;
  8.                
  9.         public class VCamera extends Sprite {
  10.                
  11.                 public function VCamera() {
  12.                         addEventListener(Event.ADDED_TO_STAGE,added);
  13.                         addEventListener(Event.REMOVED_FROM_STAGE,removed);
  14.                         addEventListener(Event.RENDER,onRend);
  15.                        
  16.                         if(stage) {
  17.                                 added();
  18.                         }
  19.                        
  20.                         visible=false;
  21.                        
  22.                         trace("new cam");
  23.                 }
  24.                
  25.                 private function added(e:Event=null):void {
  26.                         if(parent.blendMode==BlendMode.NORMAL) {
  27.                                 //if there isn't any blendmode set yet,
  28.                                 //set it as layer so that possible alpha rendering actually looks good
  29.                                 parent.blendMode="layer";
  30.                         }
  31.                         addEventListener(Event.ENTER_FRAME,eFrame,false,0,true);
  32.                         stage.invalidate();
  33.                        
  34.                 }
  35.                
  36.                 private function removed(e:Event):void {
  37.                         removeEventListener(Event.ENTER_FRAME,eFrame,false);
  38.                         parent.transform.matrix=new Matrix();
  39.                         parent.transform.colorTransform=new ColorTransform();
  40.                         parent.alpha=1;
  41.                 }
  42.                        
  43.                
  44.                 private function eFrame(e:Event):void {
  45.                         stage.invalidate();
  46.                 }
  47.                
  48.                 private function onRend(e:Event):void {
  49.                        
  50.                         //set up the movement/rotation data
  51.                         //first make a copy so that we don't corrupt the camera position
  52.                         //the getter returns a copy for us, we don't risk messing it up
  53.                         var t:Matrix=transform.matrix;
  54.                        
  55.                         //then just invert it, leaving us with the exact matrix we need to
  56.                         //get the parent into the position the camera should be in
  57.                         t.invert();
  58.                        
  59.                         //do the moving
  60.                         parent.transform.matrix=t;
  61.                        
  62.                         //people want to use these too
  63.                         parent.transform.colorTransform=transform.colorTransform;
  64.                         parent.blendMode=blendMode;
  65.                         parent.filters=filters;
  66.                         parent.alpha=this.alpha;
  67.                        
  68.                 }
  69.         }
  70. }