07-13-2012, 01:08 PM
Hello. I am trying to write a Space Shooter game in Visual Basic. Since I've started like a half hour ago, I made the player spaceship movement and the projectile launching.
The projectile launching is triggered by pressing the Space bar key. However, the same one will launch all the time. For better understanding, here are two screenshoots:
Description: Shortly after the first time I press space.
Description: Shortly after the second time I press space while the previous projectile was still in the form.
I assume you've read the image descriptions and seen what is the problem. If you still cannot understand what is the problem, let me explain better. If I just launch the projectile, it will start moving, let's say it reached the middle of the form and now I launch it again, the previous projectile won't reach the end of the form and then disappear, it will teleport to the beginning (a bit above the Spaceship).
Here is the code I use:I assume you will tell me to move the PictureBox declaration inside the Sub. I've tried that and it doesn't work since the timer which moves it cannot access the variable inside the sub.
So, the main problem is accessing the variable which is inside the sub.
When I finish the game, I will post the download link on this forum. Hopefully the game will be a decent one.
Anyway, thanks in advance.
The projectile launching is triggered by pressing the Space bar key. However, the same one will launch all the time. For better understanding, here are two screenshoots:
Description: Shortly after the first time I press space.
Description: Shortly after the second time I press space while the previous projectile was still in the form.
I assume you've read the image descriptions and seen what is the problem. If you still cannot understand what is the problem, let me explain better. If I just launch the projectile, it will start moving, let's say it reached the middle of the form and now I launch it again, the previous projectile won't reach the end of the form and then disappear, it will teleport to the beginning (a bit above the Spaceship).
Here is the code I use:
Code:
Dim pro As New PictureBox
Private Sub spawnProjectile()
pro.Image = proj
pro.Visible = True
pro.Width = 9
pro.Height = 32
pro.Top = Player.Top - 20
pro.Left = Player.Left + 20
Controls.Add(pro)
End Sub
So, the main problem is accessing the variable which is inside the sub.
When I finish the game, I will post the download link on this forum. Hopefully the game will be a decent one.
Anyway, thanks in advance.
Also known as Rocketalypse.
System.out.println("I prefer Java.");
System.out.println("I prefer Java.");