VB6 Problem, Please Help

Acer / Aspire t120c
August 19, 2009 at 03:33:38
Specs: Microsoft Windows XP Home Edition, 2.002 GHz / 735 MB
I have been recently making a small game in VB6. I decides to test the animation of the enemy which is a series of 8 bitmap images which cycles through using a lot of If-then statements.
I have done this before in a previous game which i made however in my previous game (street racer 2D) the only image that changes it the road but it doesn't move and is placed on top of each other. I used if statements to make only one image at a time visible.
In this game (Zombie Defence), I needed somthing else so I tried the following code.

Private Sub Timer1_Timer()

ZombieAnimation

End Sub

Private Sub ZombieAnimation()

If ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-1.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-2.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-2.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-3.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-3.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-4.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-4.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-5.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-5.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-6.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-6.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-7.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-7.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-8.bmp")
ElseIf ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-8.bmp") Then
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-1.bmp")
Else
   Set ZombieGrunt.Picture = LoadPicture("\Program Files\Bauer Productions\Zombie Defence\Zombie-Grunt-1.bmp")
End If
End sub

The only problem is that it dosn't work, i've spent literally hours trying to figure it out and testing it but nothing works.
The internet isn't that helpful either.

If anyone knows the problem or any other way to do what i'm trying to do them please reply.

thanks,


See More: VB6 Problem, Please Help

Report •


#1
August 19, 2009 at 04:31:07
You could try re-writing the function using the Select Case construct and using a Static variable as a counter.

When you have multiple if then statements the Select Case construct is more efficient and faster. A Static variable retains its value bewtween calls and while you code is loaded so it is best to put the Sub into a .bas module. If it is in a form module and the form is unloaded you will lose the values of the static variable. App.Path is a system variable and assumes that the BMP images are stored in the same folder as the executable file.

It ptobably wont solve your problem but it makes it easier to read and perhaps easier to understand what is going on.

Private Sub ZombieAnimation()

Static PictureCount

Select case PictureCount

Case 0
Set ZombieGrunt.Picture = app.path & "\Zombie-Grunt-1.bmp

case 1
Set ZombieGrunt.Picture = app.path & "\Zombie-Grunt-2.bmp

case 2
Set ZombieGrunt.Picture = app.path & "\Zombie-Grunt-3.bmp
.
.
.
case 7
Set ZombieGrunt.Picture = app.path & "\Zombie-Grunt-8.bmp
.
End Select

PictureCount = PictureCount + 1
if PictureCount > 7 then PictureCount = 0

End Sub

Stuart


Report •

#2
August 19, 2009 at 04:39:37
thanks,
If you want a copy of the game (or my street racer 2D) game then just e-mail me at da1da2da3ofme [AT] gmail.com.
I will send it from a different e-mail because gmail doesn't let you send .zip files. my gmail e-mail is the one which i check more often.

Report •

Related Solutions


Ask Question