Friday, March 3, 2006

Viewport Foibles

At that point in development I didn’t have much in the way of graphics. One set of graphics of a horse running – 9 different drawings, as I recall, that gave the impression of smooth animation. Like cartoons, right? But I thought I’d better get a handle on how I was going to get that animation into the viewport.

Maybe I should take a moment to talk about sprites. I learned how they work in 1983 or so when I wrote that little program on the ol’ TI-99/4A. A sprite is simply any graphic that you draw on the screen, then erase it (or re-draw the background over it), move it, and then re-draw it on the background. So it moves. Don’t know where the word “sprite” comes from, but that’s what it’s called. Now, if you want it to look a whole lot cooler you have to animate it – just like cartoonists do.

So you simply create a series of drawings on a transparent background that depict what the sprite is doing. So for my horse I created a small drawing of a horse in mid-stride, then I created another drawing with the horse’s front legs going further forward while the back legs are a little further back – and so on. With 9 “panels” the animation looked pretty convincing.

I’m not an artist, and I don’t think you need to be. If you can look at a picture and copy it in pencil, then you can scan it into a paint program and use the program’s tools to brush color over it. It’s pretty amazing how good it will look with not much effort.

At that stage the program loop wasn’t doing a whole lot of stuff. It checked to make sure the “horse” wasn’t running off the screen, it moved the background graphic sideways a couple of pixels, and checked on a number of other things, like who is in the lead, updating the elapsed time clock, etc.

But the horse animation was too jerky – and I didn’t have the program doing HALF the stuff I wanted it to do. Heck, I was only drawing one horse. I needed to draw 12! So I knew I had to find a faster way of getting the sprites on and off the screen. I started reading up on programming the Windows API (application programming interface). An API is a language that lets you write code that “talks” directly to the underlying technology. In this case that was Windows. I learned everything I needed to in order to draw the graphics directly on the Windows, er, window. By the way, I was using Windows 98 at the time.

Guess what? Still not fast enough… Still too jerky.

I had spent something like 2 months implementing the Windows API solution. Back to the drawing board. So I started reading about DirectX. DirectX8 had just come out but that seemed to be overkill for what I needed. DX8 was all about 3D graphics. I was working with scrolling 2D graphics. So I bought several books about DX7. After many weeks I figured out how to draw the graphics in DirectX7. But now I couldn’t get the viewport to be active at the same time that the dashboard was on screen.

I literally spent 3 or 4 months figuring out that problem. I wrote to I-don’t-know how many forums, read everything I could get my hands on, tried everything I could think of. I can’t tell you how now (I think I’ve blocked it from memory) but I figured out the solution – and it was FAST ENOUGH to provide me smooth horses!

That was, I’d say, the toughest challenge I overcame in my journey to completion. But there were many more to come…

Labels: , , , , , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home