Results 1 to 2 of 2

Thread: [RESOLVED] Converting Frames-per-second to Timer Interval

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    34

    Resolved [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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles animate.Click
    2.         Dim cananimate As Boolean = True
    3.  
    4.         'The secret code
    5.         If Images.Items.Count > 0 Then
    6.             Images.SelectedIndex = 0
    7.  
    8.             'While it has a image in front, keep animating
    9.             If Not Images.SelectedIndex = Images.Items.Count - 1 Then
    10.  
    11.                 Timer1.Start()
    12.  
    13.                 'If only one image present, display a message
    14.                 If Images.Items.Count = 1 Then
    15.                     MessageBox.Show("You must have more than one image to begin animating.")
    16.                 End If
    17.             End If
    18.         End If
    19.     End Sub

    Timer tick event:

    vb.net Code:
    1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    2.         If Not Images.SelectedIndex = Images.Items.Count - 1 Then
    3.             Cursor = Cursors.AppStarting
    4.             Images.SelectedIndex += 1
    5.             mainimage.Refresh()
    6.             Cursor = Cursors.Default
    7.             If Images.SelectedIndex + 1 = Images.Items.Count Then
    8.                 Timer1.Enabled = False
    9.             End If
    10.         End If
    11.     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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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