|
-
May 31st, 2000, 11:38 PM
#1
Thread Starter
New Member
im new at this vb thing and i just want to know how to make an Object(picture1) bounce inside your screen (you know like the bouncing ball screen saver) upon loading the form
-
Jun 1st, 2000, 12:08 AM
#2
Frenzied Member
the best way is to put it inside another picture box and let it bounce around that (there's a problem with borders otherwise) put picture1 inside a second picture box (picture2) then add a timer to your form and add this code
Code:
Const X_CHANGE = 10
Const Y_CHANGE = 10
Dim lngWidth As Long
Dim lngHeight As Long
Private Sub Form_Resize()
lngWidth = Picture2.Width - Picture1.Width
lngHeight = Picture2.Height - Picture1.Height
End Sub
Private Sub Picture1_Resize()
lngWidth = Picture2.ScaleWidth - Picture1.ScaleWidth
lngHeight = Picture2.ScaleHeight - Picture1.ScaleHeight
End Sub
Private Sub Timer1_Timer()
Static X As Long
Static Y As Long
'change x and y coords
X = X + X_CHANGE
Y = Y + Y_CHANGE
If X > 2 * lngWidth Then X = X - (2 * lngWidth)
If Y > 2 * lngHeight Then Y = Y - (2 * lngHeight)
Picture1.Left = Abs(X - lngWidth)
Picture1.Top = Abs(Y - lngHeight)
End Sub
my timer interval was set to 10, X_CHANGE and Y_CHANGE are how much the position of the picture box changes every timer interval, change the ratio of these to change the angle the picture box goes at
-
Jun 1st, 2000, 03:37 AM
#3
If you don't want to use a Timer Control, use the built in Timer function. Make a form with a CommandButton and a PictureBox
Put this code in a module.
Code:
Function Jump(VarVal As Control)
tmpTop = VarVal.Top
PauseTime = 0.2
Start = Timer
Do While Timer < Start + PauseTime
VarVal.Top = VarVal.Top - 1
Loop
Finish = Timer
Pausetimer = 0.2
Start = Timer
Do While Timer < Start + PauseTime
VarVal.Top = VarVal.Top + 1
Loop
Finish = Timer
Pausetimer = 0.1
Start = Timer
Do While Timer < Start + PauseTime
VarVal.Top = tmpTop
Loop
Finish = Timer
End Function
Now put this code in a CommandButton
Code:
Private Sub Command1_Click()
A = 0
Do While A < 1
DoEvents
RetVal = Jump(Form1.Picture1)
Loop
End Sub
-
Jun 1st, 2000, 04:29 AM
#4
Frenzied Member
why wouldn't you want to use a timer?
-
Jun 1st, 2000, 06:11 AM
#5
Some people, including myself, like to use as little controls as possible.
-
Jun 1st, 2000, 06:16 AM
#6
PowerPoster
Some people, including myself, like to use as little native vb commands as possible .
Use GetTickCount instead of Timer()...
-
Jun 1st, 2000, 08:05 AM
#7
PowerPoster
I prefer to use the QueryPerformanceFrequency and QueryPerformanceCounter API, beacuse it much more accurate than GetTickCount API.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|