Click to See Complete Forum and Search --> : Why doesn't this work? (source)
MetalBoy
May 16th, 1999, 01:46 AM
Is there a better way of doing this? I like how this code SHOULD work, but it flashes boxes around the sprite (GIF file w/trransparency).
Help me please.
option Explicit
Dim CurFrame
private Sub tmrAnimate_Timer()
CurFrame = CurFrame + 1
If CurFrame = 7 then CurFrame = 0
NextFrameOfGuy (CurFrame)
Beep
End Sub
private Sub NextFrameOfGuy(FrameToShow as Integer)
If FrameToShow = 0 then
Image1(0).Visible = true
Image1(6).Visible = false
else
Image1(FrameToShow).Visible = true
Image1(FrameToShow - 1).Visible = false
End If
Image2.Picture = LoadPicture("C:\visual studio\vb98\diablo\warrior\view1#\" + Trim$(Str$(CurFrame + 1)) + ".gif")
End Sub
Chris Eastwood
May 17th, 1999, 03:14 AM
Hi
On suggestion I would make is not to have 7 image controls in your project. You only really need to show one image every time the timer event happens - so just use the one image control. You probably would also do better loading the images straight from a resource file, or if it's an animated GIF OCX you're after :
http://nt1.pncl.co.uk/sbutler/vb/activex.asp
Regards
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Ravi Kiran
May 18th, 1999, 05:11 AM
Hi,
If you are having small no. of frames (7-10) as in your case, it is ok to use Image control array.
Image control is preferable than Picture box as it uses less resources.
Also, you dont need to load the pictures every time. i.e after the first sequence of 7, show the pictures from the already loaded array:
To avoid flicker, dont show & hide image controls
Instead load the images into the array and set the image property of the Other Image control.
Code could be something like this:
Make Image1 is the control array, amd Image2 displays the image on the form at approp. place.
make Image1.visible = False some where in Form load or in Properties box
private Sub NextFrameOfGuy(FrameToShow as Integer)
static m_loadedall as boolean
If m_loadedall then
image2.picture = Image1(FrameToShow).picture
else
Image1.Picture = LoadPicture("C:\visual studio\vb98\diablo\warrior\view1#\" + Trim$(Str$(CurFrame + 1)) + ".gif")
Image2.picture = image1.picture
end if
if CurFrame = 6 then m_loadedall = True
End Sub
For small images and with decently fast hdd, you may not even need the control array.
Ravi
eAs
June 14th, 2000, 07:11 AM
Because I also had the same problems, finally I used the Win32 function Bitblt from the GDI library. Actually with this function you redraw parts of an image to another image (ex the background).
This function is used very much when someone wants to make sprites through visual basic. I recommend to search with the following query ("+game+programming+visual+basic") or ("+sprites+visual+basic)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.