Search This Blog

12/14/09

Tutorial -1: Coordinate Systems

Action scripting in flash requires something more than the knowledge of the language. For any type of movement controlled by action script there is some math and some physics involved and one must have a clear understanding of it. Don’t worry it is never a lot at the beginning but something we can’t avoid and I think better we start with some basic math and some basic trigonometry. Let’s Start with the coordinate systems…… This is the first thing that a new learner has to understand

Coordinate Systems

Coordinate systems provide a way of laying out and measuring space. Probably the most common are Cartesian coordinate systems, named after the French mathematician and philosopher Rene Descartes(“I think, therefore I am”). If you have ever used a grid, you are already familiar with them. A Cartesian coordinate system is simply a set of equally spaced horizontal and vertical lines (a grid), with a horizontal axis called the x-axis and a vertical axis called the y-axis. The left graphic in Figure 1 shows a standard coordinate system. The monitor screen provides a convenient place for such a coordinate system, and we will refer to these as the screen coordinates.

Fig 1: Examples of Cartesian Coordinate Systems

Flash Coordinates and Screen Coordinates

Flash also uses a Cartesian coordinate system, shown in the right graphic of Figure 1, albeit one which is a little strange until you get used to it. In order to position objects in Flash, we will need to use Flash coordinates rather than screen coordinates. The origin or (0,0) point in the screen coordinate system is typically located in the center of the Flash Stage, and it is often convenient to use this. The origin of the Flash coordinate system is located in the upper-left corner of the Stage as shown. The main difference in the two systems is the vertical y-axis. In the screen coordinate system, positive y-values are up, while in the Flash coordinate system, positive y-values are down. To see what the transformation from the screen coordinate system to the Flash coordinate system is, let’s look at a simple example. Figure 2 shows a corresponding point in both coordinate systems.



Fig 2: Screen Coordinates and Flash Coordinates

So we can simplify it as

· If any object is moving from left to right it’s X-value is increasing

· If it is moving from right to left its X-value is decreasing.

· A downward movement means increase in Y-value

· Upward movement means decrease in Y-value.

· For any negative value of X and Y the object is placed outside the stage at the left or top respectively.

· For any positive value greater than the width and height of your stage the object will be placed outside the stage at right or at the bottom respectively.

Simple enough ha!

No comments:

Post a Comment