Would like to do animation in VB 6.0

dullard

Elite Member
May 21, 2001
25,934
4,525
126
I am a self-taught programmer, so I am not very good at it. But I would like to do a little project in VB that involves animation. When I used to use Basic, it was a piece of cake. You'd just use PUT with XOR a graphic over another. Repeat and it was gone. Then put it in the new location.

I tried to figure out how to do something similar in VB 6.0 and got nowhere. I tried PaintPicture and got nowhere. The best I could come up with was to take an image or a picture box and just change the left and top coordinates. But that didn't get me any transparancy with the complex background. Is there a way to have a image partially transparent and do it with this method?

Can anyone show me how to do simple animiation in simple terms? Or can anyone point me to a good online guide? I can Google millions of them, but I wanted to know if anyone knew of a good one.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
You would probably use Form1.Line and Form1.Circle to do it on a form (or Picture1). I haven't done a whole lot with this but I believe its paint method fires whenever the area is invalidated, that is, whenever the OS deems that the area needs repainting (you placed another window over that spot, etc). You can also use AutoRedraw=true to use the same picture that was in the back buffer (what you last drew onto that object). AutoRedraw tends to be laggy for animation though, so instead you should put your drawing code in the _Paint function.

To do animation you might use a multimedia timer from the WinMM libraries (through Win32 API), or the standard timer control included with VB which isn't too bad. The WinMM timer is a lot more accurate and is meant for multimedia stuff while the VB timer is just meant for stuff like 5-second alarm clocks and such, not stuff firing at 60Hz.

Every time this timer fires, you would set some global X and Y coordinates and invalidate the Picture object so it repaints (thru .Refresh or InvalidateRect API I believe or maybe this is even automatic). In its _Paint event you would use these new X and Y/etc coordinates to draw the object you want at that particular moment in time. The end result should be animation, but of course making a game can be a lot more complicated than this.

It's really best you use the DirectX or OpenGL APIs, for which VB libraries are quite readily available. Check out pscode.com for more VB gaming examples.
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
I haven't done any transparency blitting since 1995 with VB, so I can't give you an example at the moment (in 6 hours or so) but you were on the right path with PaintPicture.

If I remember right, you load up 2 images of the same thing, one with a white back ground, another with a black background, then in order to get transparency you have to blit the black with XOR and the white with SRCCOPY or something and it comes out transparent.

I know that wasn't much help but I vaguely remember doing something of the sort and it was with PaintPicture and those flags, and 2 images with different backgrounds.

But like xtknight said, you may be better off with a better API (DirectX/OpenGL) or use the .Net version of VB which supports alpha channels.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Ah yes if you wanted to do blitting, then you should look toward the BitBlt (and related) Win32 API which is used very often in VB and it's very stable. You can use it on any GDI object such as Forms and Pictures.
 

dullard

Elite Member
May 21, 2001
25,934
4,525
126
Originally posted by: brandonb
I haven't done any transparency blitting since 1995 with VB, so I can't give you an example at the moment (in 6 hours or so) but you were on the right path with PaintPicture.

If I remember right, you load up 2 images of the same thing, one with a white back ground, another with a black background, then in order to get transparency you have to blit the black with XOR and the white with SRCCOPY or something and it comes out transparent.

I know that wasn't much help but I vaguely remember doing something of the sort and it was with PaintPicture and those flags, and 2 images with different backgrounds.

But like xtknight said, you may be better off with a better API (DirectX/OpenGL) or use the .Net version of VB which supports alpha channels.
That is basically what I got from the MSDN, but I just couldn't get things going correctly. If you (or anyone else) could post a sample code, that would be wonderful.

Can anyone briefly describe the pros/cons of the DirectX/OpenGL to that other method?
Originally posted by: xtknight
It's really best you use the DirectX or OpenGL APIs, for which VB libraries are quite readily available. Check out pscode.com for more VB gaming examples.
Thanks, I will look into that website.
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
A good resource on starting out with directx/opengl is:
http://www.gamedev.net/reference/start_here/

I lean towards opengl because its what I use in the 3d work I do.
Also I like opengl because it works on just about any operating system out there.

If your only using windows though, directx is the way to go.