Results 1 to 9 of 9

Thread: stopping moving pictures [Resolved]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    stopping moving pictures [Resolved]

    2 Questions:
    1)
    I have a picture that moves across the form. How do I stop it when it gets to a specific point on the form.
    <code>
    Private Sub Timer1_Timer()
    Static lLeftPos As Long
    lLeftPos = Picture1.Left + 10
    If (lLeftPos + Picture1.Width) > Me.ScaleWidth Then lLeftPos = 0
    Picture1.Left = lLeftPos
    End Sub

    </code>

    2) I've sussed out how to make it go in the opposite direction by changing + to - , but how would I get it to move up or down the form?


    Any ideas appreciated
    Last edited by mbonfyre; Dec 30th, 2002 at 05:25 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    my program

    heres the prog so u can see what I'm trying to do: (get pictures 1 & 7 to stop moving when they reach the stick man)
    Attached Files Attached Files

  3. #3
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    In timer1 sub add this

    If Picture1.Left >= Picture3.Left - 1000 Then Timer1.Enabled = False

    so picture1 will stop 1000 twips or units before picture3 (stickman).

    do the same for the other two pictures.

  4. #4
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860
    VB Code:
    1. Static lLeftPos As Long
    2.     lLeftPos = Picture1.Left + 80
    3.     If (lLeftPos + Picture1.Width) > Me.ScaleWidth Then lLeftPos = 0
    4.     Picture1.Left = lLeftPos
    5.     If (lLeftPos + Picture1.Width) = 3480 Then
    6.     Timer1.Enabled = False

    ok, here's what you SHOULD do

    VB Code:
    1. 'Watch carefully as I change these 3 lines into 1
    2. 'Static lLeftPos As Long
    3. '    lLeftPos = Picture1.Left + 80
    4. '    Picture1.Left = lLeftPos
    5. Picture1.left = Picture1.left + 80 'yes you can do this
    6.  
    7.  
    8. 'Change this from
    9. '    If (lLeftPos + Picture1.Width) > Me.ScaleWidth Then lLeftPos = 0
    10. 'to
    11. if picture1.left + picture1.width > me.scalewidth then picture1.left = 0
    12.  
    13. 'I don't know what your trying to do here
    14.     If (lLeftPos + Picture1.Width) = 3480 Then  Timer1 = False

    For moving up and down, just change picture1.top (- = up, + = down)

    Or, if you want 360 degree motion, you can use this code

    VB Code:
    1. 'Subroutine for moving things
    2. Private sub Movement (byref X, byref Y, Angle, Speed)
    3. X = X + Speed * Sin(Rad(Angle))
    4. Y = Y + Speed * cos(Rad(Angle))
    5. End sub
    6.  
    7. 'This subroutine converts degrees to radians
    8. Private sub Rad(X)
    9. '3.14 is Pi, could be more precise
    10. X = X * 3.14 / 180
    11. end sub
    12.  
    13. 'and the loop..
    14. Sub timer1_timer
    15. Call movement(X,Y,0,100)
    16. end sub

    as you change angle from 0 to 360 it would move the object in a circle, beginning with east and rotating counter-clockwise (0 = east, 90 = north, 180 = west...)
    Don't pay attention to this signature, it's contradictory.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    Thanks 2 both of you for your replies. I have used the stop version Dude provided because it worked instantly, and the up/down that alcatran posted.

    I have now incountered another problem:

    I wish Timer1 to loop, but ? because of the Timer.enabled = false/ it does not work. (Or is it because I still haven't sussed loops out properly?)

  6. #6
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    Cool

    What exactly do you want to do after the pictures have stopped? Why do you need to loop?

  7. #7
    Member
    Join Date
    Dec 2002
    Location
    Miami,FL
    Posts
    34
    what Dude1 stated won't work. try placing picture1 lower than picture3 and watch, it'll stop. You have to also check if its in the range of picture3 like this

    Code:
    If Picture1.Left + Picture1.Width >= Picture3.Left And Picture1.Top >= Picture3.Top And Picture1.Top + Picture1.Height <= Picture3.Top + Picture3.Height Then
        'Stop the timer that moves picture1
    End If
    'You can put this code in the timer that moves picture1, or you can create a timer that checks for collision
    'This code only checks for collision between picture1 and picture3, im sure u can now use this code for collision between picture7 and picture3, just change around some numbers.
    Also always give your objects names it makes it easier to read

    Hope this helps
    Death is always smiling down on us, the only thing we can do is smile back

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    The program I am writing is an animation of a factory. A part is animated till it gets to a worker or machine that will assemble parts together(stop animation of single pictures and continue with a picture of the parts assembled.

    I want the loop so each time the picture stops and restarts a counter will be incremented to show the number of parts assembled.

    Here's how far I have got: lots of work to go still and some things documented in comments that aren't quite working how I expected them to
    Attached Files Attached Files

  9. #9
    Member
    Join Date
    Dec 2002
    Location
    Miami,FL
    Posts
    34
    instead of disabling the timer when the picture reaches he stick man or anything else u can just not make it move like this

    Code:
    'use the same code for checking if the picture collided, just instead of putting 
    
    If Picture1.Left + Picture1.Width >= Picture3.Left And Picture1.Top >= Picture3.Top And Picture1.Top + Picture1.Height <= Picture3.Top + Picture3.Height Then
        Timer1.Enabled = False
    End If
    
    'Put this
    If Picture1.Left + Picture1.Width >= Picture3.Left And Picture1.Top >= Picture3.Top And Picture1.Top + Picture1.Height <= Picture3.Top + Picture3.Height Then
        Picture1.Left = Picture3.Left - Picture1.Width
    End If
    
    'that prevents he timer from stopping
    Hope this helps
    Death is always smiling down on us, the only thing we can do is smile back

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