REALbasic University Resources:

RBU: Glossary Defines common REALbasic programming terms
  Archives Previously published columns
Translations: Dutch Courtesy of Floris van Sandwijk
  Japanese Courtesy of Kazuo Ishizuka
  Chinese Courtesy of Dong Li
  RBU Translation Guide Information on Translating RBU into other languages
Books: Matt's Book (2nd Edition!) Ideal for experienced programmers
  Erick's Book Best for beginning programmers
Websites: Mother Ship The publisher of REALbasic
  RB Webring Links to hundreds of REALbasic websites
  RESExcellence Another REALbasic programming column
  REALbasic Developer Magazine The premiere source for REALbasic instruction.

REALbasic University is Sponsored by

Make your Mac do what YOU want it to. Create games, utilities, cool Mac OS X tricks. Download REALbasic now and create your own software.


Print This Article

REALbasic University: Column 075

Book Review: Learning REALbasic Through Applications

Title: Learning REALbasic Through Applications
Author: Clayton E. Crooks II
Publisher: Charles River Media
Price: $41.95

There's a fascinating new REALbasic book out there which you may not have discovered. If you're new to REALbasic or to programming, you might find the unique approach to teaching in Learning REALbasic Through Applications by Clayton E. Crooks II just what you need.

Its method of teaching you about REALbasic is similar to that of REALbasic University, in the sense that we build real, practical applications and teach you as part of that process.

Learning REALbasic Through Applications is similar, except it's in book format. Each chapter is devoted to creating a different kind of application. There are 22 chapters in the book, though a few cheat and just have you build a demo instead of a real program.

Among the lessons you build an MP3 player, a calcuator, a screen saver, a movie database, a slot machine game, and an encryption program. You also create programs that use sprites, OpenGL and 3D graphics, text-to-speech, and others. The book comes with a CD that includes demos of REALbasic and all the book's projects, so you don't have to type in any code.

The broad variety of programs is excellent: you almost certainly will find a project here that's similar to something you're wanting to do. For instance, if you haven't worked with 3D graphics before, you could experiment with the 3D graphics project and learn some techniques you could use in your own programs.

However, the majority of the projects are rather basic. Most have minimal interfaces and are of the "takes ten minutes to create" variety. There's very little here you'd want to use in real life: these are just samples of things you can do with REAlbasic.

For example, here's what the MP3 player looks like:

This is the fancy (sarcasm alert) music playing program:

The graphics of the sprite example make my woeful Shooting Gallery project seem sophisticated:

Still, I like the step-by-step teaching style and feel the approach is excellent for REALbasic beginners. Intermediate users might find some projects helpful, especially in areas they're unfamiliar with, but some will wish for more advanced tips and solutions to more complicated problems. Advanced users will find little here they do not already know.

The book is 304 pages plus about 50 pages of appendixes and the index. Some of the appendixes are helpful, such as the ASCII chart, internet references, REALbasic quick reference, and a list of text encodings values. The index is competent, but not great (it's only 7 pages). I prefer a more comprehensive index, with duplicates, as my brain apparently stores stuff in the wrong manner and most indexes don't list the term under the one I look up. (For example, REALbasic University isn't listed under "R" but under "A" as Applelinks REALbasic University. That's fine, but why not do both? After all, if I remember RBU is on Applelinks, I can probably find the site without looking it up in the book.)

For new programmers or those new to REALbasic, this book is an excellent starter, though you'll grow out of it quickly. It's also a little expensive. Since it's not a reference book, you'll rarely need to go back to it again, unless there are projects you skipped the first time that you later need. It goes well as a companion book to Matt Neuburg's REALbasic: The Definitive Guide. I'd love to see a similar book geared toward advanced users with much more complicated applications.

Next Week

Something new!

Letters

Today we've got a question from Rob involving animating graphics with the timer control:

I have an application that uses a timer and a canvas to do simple animation. The canvas has a paint method that draws two objects at positions specified by global variables. The timer has an action that updates the global variables to represent new positions. It works great, except that I can't get the canvas to update faster than 30 times/second. This is even though the animation is hugely simple (two colored circles). In fact, if I take out the animation altogether, the update is STILL 30 times/second. If I update the positions via a slider control instead of the timer update, the canvas updates as fast as I like.

Do you any idea why the update is limited to 30 times/second in this case?

Great column!
Rob

Good question, Rob! I believe this is simply a limitation of the Timer control. It's well known that Timers aren't super reliable: they give a lot of time to operating system and if the system is busy, they may not execute exactly on time.

To test this, I wrote a little application in which a circle and a square race each other across a canvas. (This actually turns out to be a fun game! Try to predict which object will win.)

Within this application, I use two different methods of animation. For the first, I use a timer control. There's a slider control that lets you set the speed of the animation. At its fastest setting, a Timer's period (how often it executes) is set to 1, which should mean that the timer is run every millisecond (1,000th of a second).

However, if you try this, you'll see that even at that setting timer animation is slow.

If you click on the second button ("Race with Non-Timer Animation"), we use a tight loop to control the speed of animation:

  
dim tt as double

// This method uses a tight loop to do the animation

while (circle + 25 < canvas1.width) and (square + 25 < canvas1.width)

// Delay so the animation happens once every millisecond
tt = microseconds
while microseconds - tt < 1000
wend

circle = circle + (rnd * 10)
square = square + (rnd * 10)
canvas1.refresh
wend

if circle + 25 >= canvas1.width then
doWinner("Circle")
elseif square + 25 >= canvas1.width then
doWinner("Square")
end if

When you use this method, the racers run at a blur -- much faster than the timer method. And yet you'll see, we've included a delay within the main loop so that even here the animation can't happen faster than 1000 frames per second. Theoretically, the two methods should produce animation of similar speeds, but they do not.

On my 500-mhz PowerBook G4, I had to change the 1000 in the while microseconds - tt < 1000 line to 100,000 before it was slower than the timer method!

This just says to me that timers are lower priority controls. They're useful, but not reliable if you need exact timing. Even with the second method there is no guarantee that you'll actually be able to do timing's exactly, but it's certainly faster than using a timer. My recommendation is that you create your own timer-like system using the microseconds function to fire the animation as often as you'd like (such as 60 frames per second). However, the disadvantage to this approach is that your routine would be a CPU-hog, not giving time to the system or other aspects of your program. Depending on what you are doing, that might be okay. If not, perhaps you could spin it off in a thread.

If you want the source for this racing demo, you can grab it here.


About the Column
REALbasic University is a weekly instructional column on programming with REALbasic and is brought to you by REALbasic Developer, the magazine for REALbasic programmers.

Each week we answer select reader questions, and we're always open to ideas for future columns. Send your questions to . (Keep your questions simple and specific. General queries like "How do I write my own web browser?" will be neglected.) Your question won't be answered immediately, but will be answered in a future column. (If you don't want your correspondence published, just be sure to indicate that when you write. Otherwise it's fair game.)

About the Author
is an author, philosopher, graphic designer, photographer, film director, soccer fanatic, and programmer (among other things). He writes for MacOpinion, runs his own software company, Stone Table Software, which sells the revolutionary Z-Write word processor, and is Publisher and Editor of REALbasic Developer. He lives in Northern California with his cats, Mischief and Mayhem, and is rapidly running out of free time.

See the REALbasic University Archives


REALbasic University contents ©2001-2004 by Marc Zeedar and REALbasic Developer. All Rights Reserved.

Email This Article - Comment On This Article

.

Reader Specials

Server Racks Online:
Apple Xserve CompatibleServer Racks and Universal Network Racks
42U KVM Switch Solutions:
High-End Mac and Multi-Platform KVM Matrix switching solutions!
Digital Camera Online:
Great prices on Digital Cameras and accessories!
KVM Switches Online:
Great prices on Mac KVM Switches from the leading manufacturers!
LCD Monitors Online:
Great prices on LCD Monitors from the leading manufacturers!
LCD Projectors Online:
Shop online for LCD Projectors from the leading manufacturers!
USB 2.0 Online:
Great prices on USB 2.0 products from the leading manufacturers

Serious Business Software:
Accounting, Sales, Inventory, CRM, Shipping, Payroll & more!

KVM Switch solutions for MACs:
DAXTEN is a KVM switch, KVM extender and monitor splitter specialist for PC, SUN and MAC applications from name brand manufacturers - offices worldwide.

The "Think Different Store: The iPod Accessories Store - iPod cases, iPod mini, iPod photo, speakers, itrip, inMotion, Soundstage and all other iPod accessories

Earn Cash with the ThinkDifferent Store Affiliates Program

Need A Web Site?
Applelinks Web Hosting Starting at 19.95 a Month

iTunes_RGB_9mm

.

iTunes_RGB_9mm

Cool Mac Gear


iPod 1G-2G
iPod 3G
iPod 4G
iPod Mini
PowerBook-iBook
Keyboard Skins
Garageband