Tag Archives: matrices

Skew DisplayObject

Actionscript:
  1. var box:Shape = Shape(addChild(new Shape()));
  2. with (box.graphics) beginFill(0x006666), drawRect(0,0,50,50);
  3. box.x = box.y = 100;
  4.  
  5. addEventListener(Event.ENTER_FRAME, onLoop);
  6.  
  7. function onLoop(evt:Event):void {
  8.    
  9.     var m:Matrix = box.transform.matrix;
  10.     // skew on the X
  11.     m.c = (mouseX - stage.stageWidth / 2 ) / stage.stageWidth;
  12.    
  13.     // skew on the Y
  14.     // m.b = (mouseX - stage.stageWidth / 2 ) / stage.stageWidth
  15.    
  16.     box.transform.matrix = m
  17. }

This skews a box Shape using the c and b properties of the transformation matrix. Note that these values don't match those in the IDE's transform window. This is good further reading if your interested in this topic.

Posted in DisplayObject, motion | Also tagged , | Leave a comment