Table of ContentsGetting Some ActionMoving at an Angle

Basic Movement

Motion is something we all intuitively understand. Get up and walk across the room and you've undertaken a good bit of motion. Whether it's an apple falling from a tree or a star fighter floating through space, the concepts of movement are the same. In RoadRun you learned the basics of how to move an object around on the screen. You give it a position, and as time passes you adjust that position based on a constant speed. For example, if you place an object at position 50, 50 on the screen, and then add 1 to the y component each second, the object will move to position 50, 75 after 25 secondsa total distance of 25 pixels along the y-axis.

By adding to the y component of the position, you'll notice the object moved down on the screen. If you take away from the y position, it will of course move upwards. The same applies to adjusting the x component. By adding, you'll move to the right; subtracting will result in movement to the left.

This is the simplest form of movementconstant speed in a straight line (either horizontally or vertically in relation to the screen). Things get a little more complicated, however, if you want to move in an arbitrary direction (at an angle).

Figure 10.1. An example of basic movement by adding to the y position of an object over time.

graphic/10fig01.gif


    Table of ContentsGetting Some ActionMoving at an Angle