CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Posts
    18

    Why doesn't this work? (source)

    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





  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Why doesn't this work? (source)

    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

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Why doesn't this work? (source)

    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


  4. #4
    Join Date
    Jun 2000
    Posts
    10

    Re: Why doesn't this work? (source)

    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)



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured