Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [87]

By Root 2470 0
you can see that the new position is identical to the initial position:

x' = x*1 + y*0 + 0 = x;

y' = x*0 + y*1 + 0 = y;

Transformation Matrix


Let’s look at a few transformation matrices in ActionScript and see how they affect the presentation of the object.

You can define a matrix, and pass the value for each property into the constructor:

import flash.geom.Matrix;

// Matrix(a, b, c, d, tx, ty)

// size increases by 100% and position moved by 1 pixel on x and y axis

var myMatrix:Matrix = new Matrix(2, 0, 0, 2, 1, 1);

You can also define an identity matrix, and then apply transformation using its various methods.

Here is the code for the position transformation (shown in Figure 14-5):

var myMatrix:Matrix = new Matrix();

myMatrix.translate(2, 2);

[ 1 0 2 ]

[ 0 1 2 ]

[ 0 0 1 ]

Figure 14-5. Position transformation

Here is the code for the scale transformation (shown in Figure 14-6):

myMatrix.scale(a, d);

[ 1.25 0 0 ]

[ 0 1.25 0 ]

[ 0 0 1 ]

Figure 14-6. Scale transformation

And here is the code for the rotation transformation (shown in Figure 14-7):

// 15 represents the angle of rotation

myMatrix.rotate(15)

[ cos(15) sin(15) 0 ]

[ -sin(15) cos(15) 0 ]

[ 0 0 1 ]

Figure 14-7. Rotation transformation

Skewing does not have a method. You can implement skewing by adjusting the b and c properties of the matrix directly:

myMatrix.b = 2;

myMatrix.c = 2;

NOTE

As mentioned before, do not apply a matrix after your object is cached. You can apply a matrix for the initial transformation in place of the identity matrix, however.

Matrices for Multiscreen Deployment


Defining an initial transformation matrix other than the identity matrix is a good technique for multiscreen deployment and multiple resolutions. Create the art at one size. Detect the device resolution and scale the graphics down to the size you need, using vector graphics scalability. Then cache it:

// matrix with object scaled at 25% of its initial size

var myMatrix:Matrix = new Matrix(0.25, 0, 0, 0.25, 0, 0);

myVector.cacheAsBitmapMatrix = myMatrix;

Another advantage to using vector art is that there is no anti-alias blur or fuzzy edges. Keep in mind that if you scale up the object again, its edges will be jaggy because you are now enlarging a bitmap.

Matrices Not to Be Used in GPU Mode


Some matrices cannot be used with GPU rendering on Android along with cacheAsBitmapMatrix. These are color transformations, filters, blends, and Pixel Bender.

If you must use filters, do not use GPU mode. Convert your vector art to a bitmap and use the BitmapData.applyFilter() method. Test your application carefully, because filters and blends negatively affect performance for mobile devices.

To learn more about matrices, read Trevor McCauley’s “Understanding the Transformation Matrix in Flash 8” at http://www.senocular.com/flash/tutorials/transformmatrix/.

Hardware-Accelerated Audio and Video

Hardware acceleration is used on Android devices for other purposes without any setting up or work on your part. As we discussed in Chapter 11 and Chapter 12, hardware acceleration is used to decode AAC audio and some video codecs. Limitations are a function of the device, its driver, and its hardware decoder.

It is not recommended that you play video and use GPU rendering at the same time.

Conclusion

GPU rendering is expected to be available in other platforms as well as in Flash Player in the near future.

This concludes our discussion of APIs. You now have the tools and knowledge to build fantastic applications. The next three chapters cover best practices and building an application that uses many of these APIs.

Chapter 15. Your Device and Others

Communication works for those who work at it.

—John Powell

Your Android device, just like your laptop, has network capabilities beyond running self-contained applications or displaying Internet pages. It can communicate in real time with other devices using a local network or a capable remote server.

Developing multiuser applications opens a new dimension to any activity

Return Main Page Previous Page Next Page

®Online Book Reader