|
-
Feb 24th, 2002, 04:52 PM
#1
Thread Starter
Addicted Member
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
-
Feb 24th, 2002, 06:52 PM
#2
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.
-
Feb 24th, 2002, 06:55 PM
#3
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.
-
Feb 26th, 2002, 03:05 PM
#4
Addicted Member
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
-
Feb 26th, 2002, 07:38 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|