Stuff
OS/400 Edition
Volume 1, Number 17 -- September 26, 2002

Create an Animated Chicken with VARPG


by Shannon O'Donnell

[The code for this article is available for download.]

display

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!


Sponsored By
WORKSRIGHT SOFTWARE

On June 30, 2002,
$$$$$$$$    Postal Rates went UP!    $$$$$$$$

On July 1, 2002,
$$$$$    you wanted your postage bill to go down.    $$$$$

We have the solution! CASS certify your mailing names and addresses and presort your outgoing mail and save. Our CASS certification software ensures that your address files have valid ZIP Code and address information. Our presort software ensures that you can properly prepare you mail for delivery to your Post Office.

WorksRight Software, Inc. is the number-one source for iSeries and AS/400 CASS, presort, ZIP Code, and area code software and data.

Visit our Web site - www.worksright.com - to learn more about our CASS and presorting software, or contact WorksRight Software, Inc., phone 601-856-8337,
e-mail software@worksright.com .


THIS ISSUE
SPONSORED BY:

ASNA
Magic Software
Aldon Computer Group
ASC
Profound Logic Software
WorksRight Software


BACK ISSUES

TABLE OF CONTENTS
Introduction to Win32 API Programming with VARPG

Accessing External Data Using DB2 UDB DataLinks

Qshell Functions

Sed, the Stream Editor

Back to Basics: Multiple Subfiles on One Screen

Create an Animated Chicken with VARPG


Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Joe Hertvik
Ted Holt
David Morris
Richard Shaler

Publisher and
Advertising Director:

Jenny Thomas

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com



Last Updated: 9/26/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.