Results 1 to 7 of 7

Thread: moving images

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    19

    moving images

    i am writing a simple program that has a moving image. i want to add another image that moves randomly around the screen. how do i make the images start at random places on the screen. then move the second image move at random.

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: moving images

    Welcome to the forums.

    Are you talking about having a window with images moving around on it, or do you want a number of images moving around on the desktop?
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    19

    Re: moving images

    sorry yes the images are moving around in a frame.

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: moving images

    Shame. I quite liked the example I put together assuming that you wanted them all over the screen.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   With Timer1
    5.     .Enabled = (Forms.Count = 1)
    6.     .Interval = 100
    7.   End With
    8.   BorderStyle = 0
    9.   Left = (Screen.Width - Width) / 2
    10.   Top = (Screen.Height - Height) / 2
    11.   Picture = LoadPicture("c:\picture.jpg")
    12.   If Forms.Count < 10 Then
    13.     Dim f As New Form1
    14.     f.Show
    15.   End If
    16. End Sub
    17.  
    18. Private Sub Timer1_Timer()
    19.   Dim f As Form
    20.   For Each f In Forms
    21.     f.Left = f.Left + Rnd * 1000 - Rnd * 1000
    22.     If f.Left < 0 Then f.Left = 0
    23.     If f.Left > Screen.Width - f.Width Then f.Left = Screen.Width - f.Width
    24.     If f.Top < 0 Then f.Top = 0
    25.     If f.Top > Screen.Height - f.Height Then f.Top = Screen.Height - f.Height
    26.     f.Top = f.Top + Rnd * 1000 - Rnd * 1000
    27.   Next
    28. End Sub
    This world is not my home. I'm just passing through.

  5. #5
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: moving images

    Can you adapt the above example to do what you want?
    This world is not my home. I'm just passing through.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    19

    Re: moving images

    thanks i have a go let you know how i get on

  7. #7
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: moving images

    Just for interest sake:
    Also Note:
    NCCLog is the name of the picture

    VB Code:
    1. Private Sub TNCC_Timer()
    2. 'you could call either of the listed subs in the timer event
    3. MoveNCC
    4. 'or
    5. MoveUPD
    6. 'or
    7. MoveLER
    8. End Sub
    To Bounce on the screen walls do this:
    VB Code:
    1. Private Sub MoveNCC()
    2.     Select Case Motion
    3.         Case 1
    4.         ' Move the graphic left and up by 20 twips using the Move method.
    5.         NCCLog.Move NCCLog.Left - 20, NCCLog.Top - 20
    6.         ' If the graphic reaches the left edge of the form, move it to the right and up.
    7.         If NCCLog.Left <= 0 Then
    8.             Motion = 2
    9.         ' If the graphic reaches the top edge of the form, move it to the left and down.
    10.         ElseIf NCCLog.Top <= 0 Then
    11.             Motion = 4
    12.         End If
    13.        
    14.         Case 2
    15.         ' Move the graphic right and up by 20 twips.
    16.         NCCLog.Move NCCLog.Left + 20, NCCLog.Top - 20
    17.         ' If the graphic reaches the right edge of the form, move it to the left and up.
    18.         ' Routine determines the right edge of the form by subtracting the graphic
    19.         ' width from the form width.
    20.         If NCCLog.Left >= (Width - NCCLog.Width) Then
    21.             Motion = 1
    22.         ' If the graphic reaches the top edge of the form, move it to the right and down.
    23.         ElseIf NCCLog.Top <= 0 Then
    24.             Motion = 3
    25.         End If
    26.    
    27.     Case 3
    28.         ' Move the graphic right and down by 20 twips.
    29.         NCCLog.Move NCCLog.Left + 20, NCCLog.Top + 20
    30.         ' If the graphic reaches the right edge of the form, move it to the left and down.
    31.         If NCCLog.Left >= (Width - NCCLog.Width) Then
    32.             Motion = 4
    33.         ' If the graphic reaches the bottom edge of the form, move it to the right and up
    34.         ' Routine determines the bottom of the form by subtracting
    35.         ' the graphic height from the form height less 680 twips for the height
    36.         ' of title bar and menu bar.
    37.         ElseIf NCCLog.Top >= (Height - NCCLog.Height) - 680 Then
    38.             Motion = 2
    39.         End If
    40.    
    41.     Case 4
    42.         ' Move the graphic left and down by 20 twips.
    43.         NCCLog.Move NCCLog.Left - 20, NCCLog.Top + 20
    44.         ' If the graphic reaches the left edge of the form, move it to the right and down.
    45.         If NCCLog.Left <= 0 Then
    46.             Motion = 3
    47.         ' If the graphic reaches the bottom edge of the form, move it to the left and up.
    48.         ElseIf NCCLog.Top >= (Height - NCCLog.Height) - 680 Then
    49.             Motion = 1
    50.         End If
    51.     End Select
    52. End Sub
    To move up and down, Down and up (and right)
    VB Code:
    1. Private Sub MoveUPD()
    2. Static MDown As Boolean
    3. Static NShiftToRight As Boolean
    4. Select Case True
    5. Case NCCLog.Left + NCCLog.Width >= Me.Width
    6.     NCCLog.Move 0, 0
    7.     MDown = True
    8. Case NCCLog.Top <= 0
    9.     MDown = True
    10.     If NShiftToRight Then
    11.         NCCLog.Left = NCCLog.Left + NCCLog.Width
    12.         NShiftToRight = False
    13.     End If
    14. Case NCCLog.Top + NCCLog.Width >= Me.Height
    15.     MDown = False
    16.     NShiftToRight = True
    17.     NCCLog.Left = NCCLog.Left + NCCLog.Width
    18. End Select
    19. If MDown Then
    20.     NCCLog.Top = NCCLog.Top + NCCLog.Height
    21. Else
    22.     NCCLog.Top = NCCLog.Top - NCCLog.Height
    23. End If
    24. End Sub
    To move left to right, Right to left (and down)
    VB Code:
    1. Private Sub MoveLER()
    2. Static MRight As Boolean
    3. Static NShiftToBottom As Boolean
    4. Select Case True
    5. Case NCCLog.Top + NCCLog.Height >= Me.Height
    6.     NCCLog.Move 0, 0
    7.     MRight = True
    8. Case NCCLog.Left <= 0
    9.     MRight = True
    10.     If NShiftToBottom = True Then
    11.         NCCLog.Top = NCCLog.Top + NCCLog.Height
    12.         NShiftToBottom = False
    13.     End If
    14. Case NCCLog.Left + NCCLog.Height >= Me.Width
    15.     MRight = False
    16.     NShiftToBottom = True
    17.     NCCLog.Top = NCCLog.Top + NCCLog.Height
    18. End Select
    19. If MRight Then
    20.     NCCLog.Left = NCCLog.Left + NCCLog.Width
    21. Else
    22.     NCCLog.Left = NCCLog.Left - NCCLog.Width
    23. End If
    24. End Sub
    VB.NET MVP 2008 - Present

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