[RESOLVED] Converting Frames-per-second to Timer Interval
I have an animation program which allows users to import and animate images. I do this using timer events. I have a listbox which contains the image references, and a Image which displays the chosen image. Here is the code:
When the user clicks the "Animate" button:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles animate.Click
Dim cananimate As Boolean = True
'The secret code
If Images.Items.Count > 0 Then
Images.SelectedIndex = 0
'While it has a image in front, keep animating
If Not Images.SelectedIndex = Images.Items.Count - 1 Then
Timer1.Start()
'If only one image present, display a message
If Images.Items.Count = 1 Then
MessageBox.Show("You must have more than one image to begin animating.")
End If
End If
End If
End Sub
Timer tick event:
vb.net Code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Not Images.SelectedIndex = Images.Items.Count - 1 Then
Cursor = Cursors.AppStarting
Images.SelectedIndex += 1
mainimage.Refresh()
Cursor = Cursors.Default
If Images.SelectedIndex + 1 = Images.Items.Count Then
Timer1.Enabled = False
End If
End If
End Sub
I want to make a dialog to appear and allow the user to select a custom FPS for the animation. For instance, if they type 15, the listbox must go down 15 images in 1 second. But how do I convert FPS to a timer interval? :eek2:
Re: Converting Frames-per-second to Timer Interval
It's simple maths. What does the Interval of a Timer mean? It's the number of milliseconds between Ticks, right? That means that 1000 is one Tick per second. Simply divide 1000 by your FPS and that's your Interval. 2 FPS is an Interval of 500, 10 PFS is an Interval of 100, etc.
As I said, this is simple maths. The fact that you didn't see that is an indication that you're trying to write the code before you solve the problem. Code is not the solution to a problem; it's an implementation of the solution. You need to look at the problem in practical terms first, come with an algorithm first, then write code to implement that algorithm. If you can't solve the problem with pen and paper then you shouldn't even be considering writing code.