Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Launching Projectile [Game Issue]
#1
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:

[Image: scaled.php?server=4&filename=ssss1.png&res=landing]
Description: Shortly after the first time I press space.

[Image: scaled.php?server=802&filename=ssss2s.png&res=landing]
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
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.
Also known as Rocketalypse.
System.out.println("I prefer Java.");


Messages In This Thread
Launching Projectile [Game Issue] - by Vinwarez - 07-13-2012, 01:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Full screen game overlay? Ecnarf 1 8,114 01-29-2013, 09:14 AM
Last Post: xolara
  Dual Menu Strip Issue Moldraxian 3 15,921 08-15-2012, 12:36 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 27,598 08-13-2012, 08:58 PM
Last Post: brandonio21
  Module Issue Vinwarez 18 55,665 07-24-2012, 11:47 PM
Last Post: Vinwarez
  Remove Enemy [Game Issue] Vinwarez 3 13,558 07-14-2012, 02:15 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)