-
Movement problem
I have a code to move a bunch of arrays that are targets. this is the code
Private Sub Timer1_Timer()
Dim i
For i = 0 To 9
Target(i).Top = Target(i).Top - ((-1) ^ i) * Rnd(1) * speed
Target(i).Left = Target(i).Left - ((-1) ^ i) * Rnd(1) * speed
If Target(i).Top < 0 Or Target(i).Left < 0 Then
Target(i).Top = Me.ScaleHeight
Target(i).Left = Me.ScaleWidth
End If
If Target(i).Top > Me.ScaleHeight Or Target(i).Left > Me.ScaleWidth Then
Target(i).Top = Me.Top
Target(i).Left = Me.Left
End If
Next i
End Sub
But i have 1 problem. Every time the targets move to the top left of the screen, they would come out of the bottom right of the screen, and that is supposed to happen. BUT for some reason, when they go to the bottom right of the screen, they will come out of the top left ( like they should ) but they stay there frozen and flickering? please tell me if you know why.
Thanks
-
Re: Movement problem
You must have something else in your code...that standolane code worked just fine in an example I did.
Try that in a new project with nothing else, and see if you still experience the same issue.
-
Re: Movement problem
What are the values of Me.Top and Me.Left?
It seems odd to place the targets based on where the form is located on the desktop.
Why not just set them to 0,0, which would be the opposite corner to scaleHeight and scaleWidth.
-
Re: Movement problem
Passel is right - you should be setting the control Top and Left properties to 0 when the control has moved off the bottom-right edge of the window.
Also, you will get a smoother looking motion of controls moving outside the top-left edge of the window if you test against the bottom-right corner of the control instead of the top-left corner as follows:
Code:
Private Sub Timer1_Timer()
Dim i As Long
For i = Target.LBound To Target.UBound
Target(i).Top = Target(i).Top - ((-1) ^ i) * Rnd(1) * speed
Target(i).Left = Target(i).Left - ((-1) ^ i) * Rnd(1) * speed
If (Target(i).Top + Target(i).Height) < 0 Or (Target(i).Left + Target(i).Width) < 0 Then
Target(i).Top = Me.ScaleHeight
Target(i).Left = Me.ScaleWidth
ElseIf Target(i).Top > Me.ScaleHeight Or Target(i).Left > Me.ScaleWidth Then
Target(i).Top = 0
Target(i).Left = 0
End If
Next i
End Sub
-
Re: Movement problem
Vvmichelvv
Check the scalemode, and inform us