We help IT Professionals succeed at work.

moving images on vb (To the right)

dalebetts
dalebetts asked
on
ok im making a game on vb which needs images to move across the screen in a RIGHT direction also in random order. i need help pls
Comment
Watch Question

Author

Commented:
pls help :)
dbruntonQuid, Me Anxius Sum?  Illegitimi non carborundum.
CERTIFIED EXPERT

Commented:
Commented:
Can be very easy.
Assuming a normal VB executable project

1) Add a timer to your form (name:tm1)
2) Add a picture to your form (name:pc1)
3) Set an appropriate interval
4) Add the following code (adjust to your likings)

Not tested!!

Private Const IMAGE_SPEED = 2
Private sImages() as string

Private Sub Form_Load()
  ReDim sImages(10) as string
  sImages(0) = Me.Path & "\img1.gif"
  sImages(1) = Me.Path & "\img2.gif"
  sImages(2) = Me.Path & "\img3.gif"
  ...etc...
End Sub

Private Function GetRandomImage() as string
    Randomize
    GetRandomImage = sImages(CLng(Rnd * UBound(sImages)))
End Function

Private Sub tm1_Timer()
   pc1.left = pc1.left+IMAGE_SPEED
   If(pc1.left+pc1.width = Me.Width) Then
     
       pc1.LoadPicture(GetRandomImage)
       pc1.Left=-pc1.width
   End If
End Sub

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
As you want to develop a game, VB is not the best. BUt using the DirectX dll development kit, you can. A collegue in my team has done some tests, and with only a few lines of code, a basic shot&run game project was started...

CHeers

Author

Commented:
thx m8 i have it sorted now

Explore More ContentExplore courses, solutions, and other research materials related to this topic.