moving dots

necro
06-06-2003, 08:37 AM
i need help! does anyone know some code for some really basic moving stimuli eg dots moving constantly in one direction? any help would be really appreciated

thanks

andy

vb-dred
06-06-2003, 08:43 AM
i would use a timer, interval 1000ms, and every 1000ms it sets the image's height + 100 or something, this will move the image (dot) moving upwards.

necro
06-06-2003, 09:04 AM
i would use a timer, interval 1000ms, and every 1000ms it sets the image's height + 100 or something, this will move the image (dot) moving upwards.

cool, but would you be able to give me a quick example

thanks

andy

vb-dred
06-06-2003, 09:09 AM
say you got a image named img1 and a timer named tmr1, interval set to 1000.
put this in your coding

Private Sub Tmr1_Timer()
Img1.Top = Img1.Top + 100
End Sub


this would make the image go down every 1 second

necro
06-06-2003, 09:15 AM
i use a library called winhrt to do my timing so i suppose it would then be

img1.top = img1.top + 100
do_idelay1 'my thing e.g. 500ms
img1.top = img1.top + 100

etc

necro
06-06-2003, 09:43 AM
ok cool this works (with my module timer thing) so i can get it to go left and down (.left and .top) but how do i get it to go right and up?

thanks

andy

DrPunk
06-06-2003, 11:27 AM
ok cool this works (with my module timer thing) so i can get it to go left and down (.left and .top) but how do i get it to go right and up?

thanks

andy
Hi. I get the feeling that you're trying to get something to bounce around the form. Even if it's not, it got me interested so I decided to put a pretty poor example together. These are my first thoughts on it. No doubt there is some much simpler way of doing it. I'm afraid it doesn't even take into account the title bar of the window so goes off the bottom of the window a bit.

If you want to do stuff like this I advise you look intousing pictureboxes and blitting and the like because using controls gives nasty flickers. Anyway, it was fun while it lasted.

Just change C_MOVE to move the control by more or less. It's all twips. I suppose I should of used ScaleHeight and ScaleWidth so it would work in pixels too. Oh yeah, and it uses a shape control.

Option Explicit

Private Const C_MOVE = 60

Private m_Up As Boolean
Private m_Left As Boolean

Private Sub Timer1_Timer()
If WillHitBoundaryX Then
m_Left = Not m_Left
End If

If WillHitBoundaryY Then
m_Up = Not m_Up
End If

Shape1.Left = Shape1.Left + MoveByX
Shape1.Top = Shape1.Top + MoveByY
End Sub

Private Function WillHitBoundaryY() As Boolean
If Shape1.Top + MoveByY <= 0 Then
WillHitBoundaryY = True
Else
If Shape1.Top + Shape1.Height + MoveByY >= Me.Height Then
WillHitBoundaryY = True
End If
End If
End Function

Private Function WillHitBoundaryX() As Boolean
If Shape1.Left + MoveByX <= 0 Then
WillHitBoundaryX = True
Else
If Shape1.Left + Shape1.Width + MoveByX >= Me.Width Then
WillHitBoundaryX = True
End If
End If
End Function

Private Function MoveByX() As Long
If m_Left Then
MoveByX = -C_MOVE
Else
MoveByX = C_MOVE
End If
End Function

Private Function MoveByY() As Long
If m_Up Then
MoveByY = -C_MOVE
Else
MoveByY = C_MOVE
End If
End Function

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum