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.
If (lLeftPos + Picture1.Width) > Me.ScaleWidth Then lLeftPos = 0
Picture1.Left = lLeftPos
If (lLeftPos + Picture1.Width) = 3480 Then
Timer1.Enabled = False
ok, here's what you SHOULD do
VB Code:
'Watch carefully as I change these 3 lines into 1
'Static lLeftPos As Long
' lLeftPos = Picture1.Left + 80
' Picture1.Left = lLeftPos
Picture1.left = Picture1.left + 80 'yes you can do this
'Change this from
' If (lLeftPos + Picture1.Width) > Me.ScaleWidth Then lLeftPos = 0
'to
if picture1.left + picture1.width > me.scalewidth then picture1.left = 0
'I don't know what your trying to do here
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:
'Subroutine for moving things
Private sub Movement (byref X, byref Y, Angle, Speed)
X = X + Speed * Sin(Rad(Angle))
Y = Y + Speed * cos(Rad(Angle))
End sub
'This subroutine converts degrees to radians
Private sub Rad(X)
'3.14 is Pi, could be more precise
X = X * 3.14 / 180
end sub
'and the loop..
Sub timer1_timer
Call movement(X,Y,0,100)
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.
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
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
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