Results 1 to 13 of 13

Thread: i need help with my game

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    i need help with my game

    I am trying to get an array of images to move in sequence. however when the value of i changes, one the barrel stops rolling and another one starts. how would i get them to continue rolling after the value of i changes. i have tried many different loops but i cant really get it to work.

    Private Sub tmrbarrel_Timer()
    If Image3(i).Visible = True Then
    Image3(i).Left = Image3(i).Left + 25
    End If
    End Sub

    Private Sub tmrcounter_Timer()
    i = i + 1
    Image3(i).Visible = True
    End Sub

    Thanks in advance

  2. #2
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: i need help with my game

    Well for starters, its never a good idea to use Timers for games. Timers are bad and get worse the more timers you use because all of the code in one timer must complete before the next one can even fire. If you need help constructing a realtime game loop. I can help you with that. As for your code. If you want all of them to move, use a For loop to loop through all of the barrels you want to move. The number of barrels could actually be placed in the Form_Load statement with the "Dim Number_Of_Barrels As Long" declared on top in the General Declarations.

    vb Code:
    1. Private Sub tmrbarrel_Timer()
    2.      Dim Number_Of_Barrels As Long
    3.  
    4.      Number_Of_Barrels = 10
    5.  
    6.      For i = 0 to Number_Of_Barrels - 1
    7.           If Image3(i).Visible = True Then
    8.                Image3(i).Left = Image3(i).Left + 25
    9.           End If
    10.      Next i
    11. End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: i need help with my game

    i typed in that code. however only 1 barrel will move now.
    btw thanks for helping

  4. #4
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: i need help with my game

    Why only one barrel? Probably has to do with the visible tag. Plus you may wanna stop that other timer.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: i need help with my game

    idk all that happens is one of the images will continue to increase its left value to the end of the screen.
    the other images in the array dont do anything

  6. #6
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: i need help with my game

    Are all of your barrels visible? Basically assuming they were (you may wanna comment that visible line out as a test) it should have moved 10 of your barrels to the right. Plus if you need collision when it collides into something, let me know cause I dont know how your games played. Better yet, could you upload your entire project in a zipfile so I can see?

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: i need help with my game

    Quote Originally Posted by Jacob Roman View Post
    Plus you may wanna stop that other timer.
    tmrcounter, why?

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: i need help with my game

    Oh i found out whats wrong. when i run this it moves all of the images at the same time. So since they all start off in the same place, it just looks like one object is moving. i wanted to move 1 every time tmrcounter runs. sry i should have specified.

  9. #9
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: i need help with my game

    Because the other timer is using a For loop. Timers must complete the code before the next timer can fire, thats why timers are horrible and should never be used for games. Instead its better to use a realtime game loop.

    Basically this is what the codes doing I gave you for tmrbarrel_Timer:

    For i = 0 To Number_Of_Barrels - 1 'Loops through all 10 barrels.
    If Image3(i).Visible = True Then 'Checks if they are Visible. If they are, move them
    Image3(i).Left = Image3(i).Left + 25 'Moves all the barrels to the right
    End If
    Next i 'Goes back up to the for loop to the next barrel until it completes the entire duration.

    If you want it to move it one at a time and have the next one move along with the others in sequence, start the Number_Of_Barrels = 1, and have your other timer
    do Number_Of_Barrels = Number_Of_Barrels + 1 instead of i.

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: i need help with my game

    thank u

  11. #11
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: i need help with my game

    Out of curiosity, what game are you making? Donkey Kong?

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Posts
    15

    Re: i need help with my game

    yup

  13. #13
    College Grad!!! Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: i need help with my game

    Hmmm interesting. But for the real thing, try playing my Nintendo Emulator I wrote in VB6 and download Donkey Kong like off of www.coolrom.com. You can find my emulator in my signature.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width