Results 1 to 5 of 5

Thread: How to set up a loop

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    How to set up a loop

    How do I set up a loop using Gettickcount to do an animation for a certain amount of time, say for 2 seconds?

    Thanks

  2. #2
    Zaei
    Guest
    Simply take the number of frames in the animation, and divide that by the number of milliseconds that you want it to play (2000ms, in your case).
    Code:
    ' in animation code
    ' lastAnimTick is the last time a frame was switched
    ' num_ms = 2000
    ' frames_in_anim = number of frames in animation
    ' nextFrame is the index of the next animation frame
    If GetTickCount() > lastAnimTick + (num_ms / frames_in_anim) Then
       SwitchFrame(nextFrame)
       nextFrame = nextFrame + 1
    End If
    I am assuming a 2d animation here, by the way. For 3d, its a bit more complicated.

    Z.

  3. #3
    Zaei
    Guest
    The above was for playing one animation loop smoothly over a period of time. If you have an animation you want to play over and over again for a period of time, use this:
    Code:
    Dim sTime as Long
    Dim PlayAnim as Boolean
    Dim currFrame as Long
    currFrame = 0
    sTime = GetTickCount()
    PlayAnim = True
    While bRunning ' main loop
         If GetTickCount() > sTime + 2000 Then
              PlayAnim = False
         End If
         If PlayAnim Then
              SetFrame(currFrame Mod frames_in_anim)
              currFrame = currFrame + 1
         End If
    Wend
    Z.

  4. #4
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Add 'Call ' onto the beginning of his SetFrame and SwitchFrame lines. Otherwise VB will get upset about the floating parentheses.

    Been coding too much C++, eh zae?
    "1 4m 4 1337 #4xz0r!'
    Janus

  5. #5
    Zaei
    Guest
    Never too much. VB is just strange =).

    Z.

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