Animation Using Timer&Media Player in VB 6

download Animation Using Timer&Media Player in VB 6

of 21

Transcript of Animation Using Timer&Media Player in VB 6

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    1/21

    MS WINDOWS

    MEDIA PLAYER

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    2/21

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    3/21

    Commandone for Play button

    Command Two for Stop buttonCommand three for PauseCommand four foropen.

    Press ctrl+t for componentsSelect Wi

    ndow M

    edia

    Player

    Select Common Dialog 1 button

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    4/21

    _MediaPlayer1.Play

    End Sub

    Private Sub Command2_Click()

    MediaPlayer1.Stop

    End Sub

    Private Sub Command3_Click()

    MediaPlayer1.Pause

    End Sub

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    5/21

    CommonDialog1.ShowOpe

    nMediaPlayer1.Open

    CommonDialog1.FileNameEnd sub

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    6/21

    Command2.Top = Form1.Height -1000

    Command3.Top = Form1.Height -1000

    Command4.Top = Form1.Height -1000

    End Sub

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    7/21

    End Sub

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    8/21

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    9/21

    Animation using timer

    To make it move automatically, you need touse a timer. The first step in creating

    automatic animation is to drag the timer fromthe toolbox into the form and set its intervalto a certain value other than 0. A value of 1 is1 milliseconds which means a value of 1000

    represents 1 second. The value of the timerinterval will determine the speed on ananimation.

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    10/21

    Use a very simple technique to

    show animation by using theproperties Visible=False andVisible=true to show and hidetwo images alternately. Whenyou click on the program, you

    should see the followinganimation.

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    11/21

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    12/21

    Put first image onsecond image1 visible true2 visible false

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    13/21

    Animation using timer

    Private Sub Timer1_Timer()

    If Image1.Visible = True Then

    Image1.Visible = FalseImage2.Visible = True

    Else If Image2.Visible = TrueThen

    Image2.Visible = FalseImage1.Visible = True

    End If

    End Sub

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    14/21

    Animation using timerYou need to insert a group of

    eight images of a butterfly

    flapping its wings at differentstages. Next, insert a timer into

    the form and set the interval to 10or any value you like. Remember

    to make image1 visible whileother images invisible at start-up.

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    15/21

    Animation using timerFinally, insert a command button,rename its caption as Animate

    and key in the followingstatements by double clicking onthis button. Bear in mind that youshould enter the statements for

    hiding and showing the imagesunder the timer1_timer subroutine

    otherwise the animation wouldwork.

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    16/21

    Animation using timer

    Clicking on the animate buttonmake timer start ticking andthe event will run after everyinterval of 10 milliseconds or

    whatever interval you have setat design time

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    17/21

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    18/21

    The codes Private Sub Form_Load()

    Image1.Visible = True

    x = 0End Sub

    Private Sub Command1_Click()

    Timer1.Enabled = TrueEnd Sub

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    19/21

    The codes Private Sub Timer1_Timer()

    If Image1.Visible = True Then

    Image1.Visible = FalseImage2.Visible = True

    Else If Image2.Visible = True Then

    Image2.Visible = FalseImage3.Visible = True

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    20/21

    The Codes Else If Image3.Visible = True Then

    Image3.Visible = False

    Image4.Visible = TrueElse If Image4.Visible = True ThenImage4.Visible = FalseImage5.Visible = TrueElse If Image5.Visible = True Then

    Image5.Visible = FalseImage6.Visible = TrueElse If Image6.Visible = True ThenImage6.Visible = False

  • 8/9/2019 Animation Using Timer&Media Player in VB 6

    21/21

    The Codes Image7.Visible = True

    Else If Image7.Visible = True Then

    Image7.Visible = FalseImage8.Visible = TrueElse If Image8.Visible = True ThenImage8.Visible = False

    Image1.Visible = TrueEnd IfEnd Sub