Recipe 10.4. Shearing


Problem

You want to shear (skew) a display object.

Solution

Create a Matrix object with default values, without the b and c properties. The b and c properties control the y and x shearing, respectively. Assign the Matrix object to the transform.matrix property of the display object.

Discussion

Shearing (or skewing) fixes a point on a plane and translates all the pixels on one side of the point in one direction and all the pixels on the opposite side equally in the opposite direction. The effect is that a rectangle becomes a parallelogram.

The flash.geom.Matrix class defines a, b, c, d, tx, and ty properties. The b and c properties determine how much skewing is applied (whereas a and d determine the scale factor and tx and ty determine the x and y TRanslation). The b property determines skewing along the y axis, and the c property determines skewing along the x axis. The default values for the b and c properties are 0. The greater the values, the greater the skewing is down and to the right. Negative values skew the object up and to the left. The following code draws a square and skews it into a parallelogram along the y axis. The Matrix object uses the default values for the properties, except for b, which is assigned a non-default value of 1. (The default values are a=1, b=0, c=0, d=1, tx=0, and ty=0.)

var box:Sprite = new Sprite(  ); box.graphics.lineStyle(  ); box.graphics.drawRect(0, 0, 100, 100); addChild(box); box.transform.matrix = new Matrix(1, 1, 0, 1, 0, 0);




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net