|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Images Move Freely
I dont know if any of you have heard of these games:
Pong Rebound Smashing But they all have one thing in common, they have a ball that moves freely without clicking the mouse or pressing a key. Thats what i am trying to do. Can you help me with a code or something? ![]() |
|
#2
|
||||
|
||||
|
Definitely heard of pong. I once wrote it in Javascript (although it's not complete. Have a few bugs to sort out, which is where I usually quit).
What you must do is insert a timer into your form. Set the timer's interval to 1 (in milliseconds). Then, in the timer code, you insert the code to move the ball. I usually have a variable: intTop, and intLeft to specify if it should move left or right. Here's the untested code: Code:
Dim intLeft
Dim intTop
Dim iPosTop
Dim iPosLeft
Private Sub Form_Load()
iPosTop = btntest.Top
iPosLeft = btntest.Left
intLeft = 7
intTop = 7
End Sub
Private Sub Timer1_Timer()
iPosTop = iPosTop + intTop
iPosLeft = iPosLeft + intLeft
If (iPosTop >= (Form1.Height - 2 * btntest.Height)) Or (iPosTop <= 0) Then
intTop = intTop * -1
iPosTop = iPosTop + intTop
End If
If (iPosLeft >= (Form1.Width - btntest.Width)) Or (iPosLeft <= 0) Then
intLeft = intLeft * -1
iPosLeft = iPosLeft + intLeft
End If
btntest.Top = iPosTop
btntest.Left = iPosLeft
End Sub
I used a button called btnTest instead of a picture. By changing the values of intleft and inttop, you can make it move slower or faster, and at angles (e.g. setting inttop to 10 and intleft to 20, it will move more horizontically than vertically) Last edited by Silian : August 25th, 2003 at 03:04 AM. |
|
#3
|
|||
|
|||
|
Moving a ball
Hi, I'm interested in this as well, I've done darkBasic for a year and I got most of the math stuff sorted out (I even know most of the code for a car sim
, but now I'm kind of back to square one just learning how vb itself works. If you still need any code for it I can go and dig it out. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Images Move Freely |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|