|
Intro to Two-Dimensional Animation in Visual Basic It is easy to create animations using Visual Basic. The basic idea is that you place a series of images on your form and then you control which image is displayed in the order you wish. Creating animation in Visual Basic starts with using the timer. The technique is simple. You place a series of images on your form. You set the visible property to FALSE on all but the first image. Then, the timer controls which image is visible by looping through the images. The effect is just like an animation flipbook. When the timer flips through the images fast enough, it looks like the image is moving. Animation is made possible by two important programming principles: the loop and the control array. A loop is a part of the program which keeps repeating itself for as long as you tell it to do so. The flickering of an animation is nothing more than a series of images that are looping. A control array is a special type of "shortcut" that you as a programmer can use to make the computer process faster. In Visual Basic, you automatically create a control array when you copy and paste the same object on your form. Let's say you have just made a picture box named "picture" and placed it on your form. If you copy and paste the picture again, Visual Basic will stop you and tell you that you already have a picture by that name. It then asks you if you wish to create a control array. If you go along and paste the picture, you will see that you have started to create a sequence that looks like this: picture(0) picture(1) picture(2) All that's happening here is that the computer is using the same name (picture) over and over with the addition of index numbers so that it can tell them apart. That's really all there is to creating a control array. Now, the processor can operate more efficiently because the array allows the computer to refer to all the pictures (called elements) under the same name by referring to each element's index number. You may be thinking, "what's the big deal? Why bother creating a control array?" Imagine an animation that contained a thousand pictures--or ten thousand pictures--would you want to come up with different names for each? A video game can have hundreds of thousands of images. Without arrays, it would impossible to control all the images. Animation depends on using arrays, so it's important to get used to using them. Okay, let's create a simple 2D animation:
Create an animation that displays eight shapes (or pictures) in a circle |