View Full Version : My History Project...
zesti
05-07-2004, 09:21 PM
For my history project I am building a game that relates to History in VB. What I am trying to do is drop a "circle" in to a maze and have it bounce around. This is just a basic animationd of the circle freefalling. My problem is that I can't see the process...it just ends up at Chip.Top = 2040. Im guessing I need to add mabye some timer process's in between to delay the freefalling.
Private Sub Label10_Click()
Chip.Left = 1800
Chip.Top = 1560
Chip.Top = 1680
Chip.Top = 1800
Chip.Top = 1920
Chip.Top = 2040
End Sub
Could someone tell me plz?
Yep. VB will just execute one line after another, WITHOUT refreshing the interface, and all that you will see is your last assignment.
You could put the "DoEvents" function in between each item, or create a Wait function like this:
Public Sub Wait(dSeconds as Double)
' Declare a Timer that is dSeconds ahead of now...
Dim dFutureTime as Double
dFutureTime = Timer + dSeconds
' Wait until we reach that future time...
Do While dFutureTime > Timer
DoEvents
Loop
End Sub
and add the function in between your calls:
Chip.Left = 1800
Wait 2
Chip.Top = 1560
Wait 2
...
zesti
05-14-2004, 03:52 PM
Private Sub Label10_Click()
Chip.Left = 1800
Wait 2
Chip.Top = 1560
Wait 2
Chip.Top = 1680
Wait 2
Chip.Top = 1800
Wait 2
Chip.Top = 1920
Wait 2
Chip.Top = 2040
End Sub
Public Sub Wait(dSeconds As Double)
' Declare a Timer that is dSeconds ahead of now...
Dim dFutureTime As Double
dFutureTime = Timer + dSeconds
' Wait until we reach that future time...
Do While dFutureTime > Timer
DoEvents
Loop
End Sub
This is what I put in according to your advice (must have misenterperated). I didn't get any errors but it did not wait at all between free falls. Just so you know the timer on that form is named "Timer".
Plz tell me what im doing wrong this time :)
You don't need a Timer control on the form. "Timer" is a built-in function in VB that returns the numbers of seconds that have elapsed since midnight. So, you can remove the Timer control and just use the code as it is.
I just cut and pasted your code from above into a new VB project, then added a label control (which I named "Label10", so that the code would get called) and a push button named "Chip." After running the program and clicking the label, the button did indeed change positions a number of times, waiting two seconds in between jumps.
zesti
05-22-2004, 09:43 PM
It all works now except for the fact that I don't want a command button, I want a circle to move. Is this possible?
It all works now except for the fact that I don't want a command button, I want a circle to move. Is this possible?
Sure. Just use the Shape control from the toolbox to put a circle on your form. Give the control a name and use that name in your statements above.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.