|
|
![]() |
|
|
Create an Animated Chicken with VARPG by Shannon O'Donnell [The code for this article is available for download.]
Here's a fun little exercise for you to try, which, if you are successful, will result in a VisualAge for RPG application that displays an animated chicken. It's not your normal, every day business application, but what the heck! You've been working hard all week. Now it's time for a little fun. Let's see how it's done. The Pieces Creating animation with VARPG is surprisingly easy. All you really need are the images that make up your animation, a window with canvas part, an image part to display them on, and a timer part to perform the animation.
Before you get started here, download the .zip file that accompanies this article. This .zip file contains four bitmap images. Next, create a new VARPG GUI project. Name the window with canvas part WIN1. Add an image part, and name it IMG1. Add a timer part, and name it Timer1. Add a push button part, and name it PSBEXIT. Then add a PRESS event to the push button part, and add the code: <I>C Eval *INLR = *ON</I> Add a CREATE event to the window with canvas part, and add the following line of code to it: <I>C 'Timer1' setatr 1 'TimerMode'</I> One last thing. Add a D-spec to your source code and add a numeric variable named Counter to it. Now Save your project, and give it some memorable name. Associating the Images Unzip the file you downloaded for this article. The files should be unzipped (or copied) to the directory named RT_WIN32, which (generally) can be found under the directory C:\WDT400\projects\VARPG Projects\YOUR_PROJECT_NAME\. If you are using the new version of the WebSphere Development Tools, replace WDT400 in this example with WDSC. Also, note that YOUR_PROJECT_NAME in this example is the name you saved your animation project as. Keep in mind that, depending upon how you named and saved the project, your directory structure may be slightly different. Click the image part and select Properties. Click the STYLE tab, then click the Find button. Navigate to the RT_WIN32 directory you copied the download files to, and select CHICK1.BMP. The Animation Code The final piece to make your animation work is to set the FileName property of the image part to the next logical animation image. Let the VARPG application automatically set this image for you by using the timer part. Once the timer part has been started (which occurred when the Window was first created, as it was initiated), a countdown will begin. Once the countdown has reached the interval specified for that timer part (specified at either Design or Runtime), the timer part's TICK event will be fired. Each time the TICK event is fired, your VARPG code will change the bitmap image in the image FileName property. Here's the code you'll need to add to the TICK event for the timer part.
C TIMER1 BEGACT TICK WIN1
*
C Select
C When Counter = 0
C Eval Counter = Counter + 1
C Eval %Setatr('WIN1':'IMG1':'FileName')=
C 'Chick2.BMP'
C When Counter = 1
C Eval Counter = Counter + 1
C Eval %Setatr('WIN1':'IMG1':'FileName')=
C 'Chick3.BMP'
C When Counter = 2
C Eval Counter = Counter + 1
C Eval %Setatr('WIN1':'IMG1':'FileName')=
C 'Chick4.BMP'
C When Counter = 3
C Eval Counter = 0
C Eval %Setatr('WIN1':'IMG1':'FileName')=
C 'Chick4.BMP'
C EndSl
*
C ENDACT
Grab Some Popcorn That's it. Compile the application, and grab a bag of popcorn. It's time for cartoons!
|
Editors
Contact the Editors |
|
Last Updated: 9/26/02 Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |