banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

Application of Matrix Transformation MatrixTransformer in ActionScript Learning Notes

ActionScript Learning Notes: Application of Matrix Transformation MatrixTransformer

Flash ActionScript Matrix
Flash supports matrix operations to achieve matrix transformations on display objects, allowing for translation, scaling, rotation, and skewing of objects using matrix operations.
The specific usage is as follows:
Define a matrix object -> Perform parameter operations on the matrix -> Apply matrix transformation to the desired display object

Define a matrix:

import flash.geom.Matrix;
var myMatrix: Matrix = new Matrix();

Perform the corresponding matrix transformations on the matrix:
Translation:

translate(a, b)
// a represents the distance of horizontal translation
// b represents the distance of vertical translation, in pixels

Scaling:

scale(x, y)
// x represents the horizontal scaling factor, default is 1
// y represents the vertical scaling factor

Rotation:

rotate(a)
// a represents the rotation angle, with the object's (0,0) point as the rotation center, can be negative
// Use radians for calculations, for example, use the conversion: 2 * Math.PI * (-30 / 360) to represent -30°
// Rotate left by 30 degrees

Skewing:

skew(a, b)
// a represents the horizontal skewing
// b represents the vertical skewing, in radians

Apply matrix transformation:

var demo = new DisplayObject();
demo.transform.matrix = myMatrix;

Here is a complete demonstration implementation:
Horizontal translation by 10, vertical translation by 20;
Horizontal scaling by 2, vertical scaling by 0.5;
Rotate right by 30 degrees;
Horizontal skew by 10, vertical skew by 20.

import flash.geom.Matrix;
var myMatrix = new Matrix(); // Define a new Matrix
myMatrix.translate(10,20); // Translation
myMatrix.scale(2,0.5); // Scaling
myMatrix.rotate(2 * Math.PI * (30 / 360)); // Rotation
myMatrix.skew(10,20); // Skewing
demo.transform.matrix = myMatrix; // Apply Matrix transformation to demo

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.