|
-
Jun 30th, 2000, 11:31 AM
#1
Thread Starter
New Member
Hello!
I am new to VB. I have been experimenting with it and would like to learn even more. I have been trying to figure out how to get pictures to move randomly across the screen. Can any one help? I would like to do 2 or more pictures but one would be enough to start.
Thanks in advance.
In order to succeed you don't necessarily have to fail, but you have to keep going till you get it right.
-
Jun 30th, 2000, 03:06 PM
#2
Try this and see if it is what you want. Make a Form with an ImageBox and a Timer. Set the Interval for the Timer to 1. Also, make sure there is a piucture loaded into the ImageBox.
Put this code in the Timer.
Code:
Private Sub Timer1_Timer()
Dim Direction As Byte
Dim Length As Integer
Randomize
Direction = Int(Rnd * 4) + 1
Length = Int(Rnd * 500) + 1
Select Case Direction
Case 1
Image1.Left = Image1.Left + Length
Case 2
Image1.Left = Image1.Left - Length
Case 3
Image1.Top = Image1.Top + Length
Case 4
Image1.Top = Image1.Top - Length
End Select
End Sub
-
Jun 30th, 2000, 05:54 PM
#3
transcendental analytic
Here's some cooler effects, random controlled direction
Use a image control image1, modify it for your needs 
Code:
Option Explicit
Private Sub Form_Activate()
Dim x As Single, y As Single, velocity As Single, angle As Single, vangle As Single
velocity = 2
angle = Rnd * 6.283
x = image1.Left: y = image1.Top
Do
If Rnd < 0.1 Then vangle = (Rnd - 0.5) * 0.5 'Change direction velocity randomly 10%chance
angle = angle + (vangle + 6.283) Mod 6.283 'change direction
x = x + Cos(angle) * velocity 'move position
y = y + Sin(angle) * velocity
image1.Move x, y 'move image
DoEvents 'threading
Loop While Forms.Count or yourchoise
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|