Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Whats wrong with my bullet?

Author
Message
Ulnarian
15
Years of Service
User Offline
Joined: 29th Apr 2009
Location:
Posted: 2nd May 2009 10:33
Hey all, so I have a pretty basic code and I've hit this problem that is driving me crazy.

Basically, a spaceship (sprite 2) is supposed to fire a bullet (sprite 3) when the user presses the Shift key. Here's the code so far:



The problem is, the bullet will always appear at the top of my screen around the (y=30) position or so, not at the y=600 position.

Does anyone know why this would be the case. My guess is that this code here is the culprit:



Thanks
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 2nd May 2009 15:59
Your first line is odd. Should y not be declared global as your only reference to it is in a function?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd May 2009 16:00
Your sprite is only being moved when you hold down the shift key, and your y coordinate for it isn't being reset each time you fire.

Use something like this:


Basically, you don't need that 'y' variable for something like this.

Login to post a reply

Server time is: 2024-09-28 06:24:03
Your offset time is: 2024-09-28 06:24:03