Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-27-2007, 10:34 PM   #1
JohnnyTightLips
Registered User
 
Join Date: Aug 2005
Posts: 87
Default Shooting Problem...

I am having some trouble with the shooting aspect in my side-scrolling game.
So far, I've made the bullet invisible, and when a key is pressed it becomes visible and starts moving in the proper direction. The problem is, once I let go of the key, the bullet just stands still in mid-flight. I've tried adding some code and getting rid of some others, but does anyone know a way that I can achieve this?

P.S. If my explaining of the problem or what I want the solution to be is unclear, tell me and I'll try to tell you in a different way what I mean.

Thanks in advance - JohnnyTightLips
JohnnyTightLips is offline   Reply With Quote
Old 03-31-2007, 08:54 PM   #2
Def Gie
deaf guy
 
Def Gie's Avatar
 
Join Date: Jul 2006
Posts: 183
Default

My guess is that you're using isDown to detect whether the key is pressed, and if so, moving the bullet:
ActionScript Code:
if(/*the key is pressed*/){ bullet._visible = true; bullet._x += speed; }
or some such thing. The trouble then is that it only moves the bullet if the key is down. As soon as you release the key, the bullet stops. Instead you should probably use something more like this:
ActionScript Code:
if(/*the key is pressed*/){ bullet._visible = true; bullet.onEnterFrame = function(){ this._x += speed; } }
That way it sets the bullet to move every frame when the key gets pressed.
__________________
The only way to debug a program is by the Scientific Method
1. Define the problem (What is your bug?).
2. Collect information (Make sure all functions do what you think, watch variables).
3. Form a hypothesis (Propose a cause of the bug).
4. Test the hypothesis (Run the program with that factor different).
5. Make a conclusion (Figure out what's happening and how to fix it).
Don't bother communicating the results.

The text has been frozen!!!
Def Gie is offline   Reply With Quote
Old 04-07-2007, 12:37 AM   #3
JohnnyTightLips
Registered User
 
Join Date: Aug 2005
Posts: 87
Default

Thanks so much Def Gie, that helped me a lot. But now I seem to be having other problems that I cannot solve.

1) When I shoot and let go of the shooting button, the bullet now moves in the proper direction (thanks to Def), but when I use my other-direction-shooting button, the same bullet turns around and goes the other way. Is there a way I can say: "When you let go of this key, you have no control of the bullet untill it dissapears"?

2) I tried to set my code so that when the bullet hits a certain x-coordinate, that the bullet dissapears, but then when I test my game, the bullet still passes through and doesnt't dissapear. What is the proper code I should use for a situation like this?

Thanks in advance for any help - JohnnyTightLips
JohnnyTightLips is offline   Reply With Quote
Old 04-07-2007, 06:02 PM   #4
Def Gie
deaf guy
 
Def Gie's Avatar
 
Join Date: Jul 2006
Posts: 183
Default

1) How about something such as,
ActionScript Code:
if(/*the key is pressed*/ && bullet._x == /*the starting _x of the bullet*/){ /*Set the bullet to move as before*/ }
so that it only sets the bullet to move if it's where it starts.

2)I can only guess at this one, but I have a few ideas. I think you should try using >= to check if it's at or past a certain coordinate, rather than == to check if it's at the coordinate. Sometimes incremented variables unexpectedly skip values you want them to hit (usually because they're not whole numbers to begin with). Then you'll want to make it invisible again and restore its original coordinates, right? Be sure to also set
bullet.onEnterFrame = null;
or
delete bullet.onEnterFrame;
in the process or it will keep moving after you hide and return it.
As usual, I hope that helps.
__________________
The only way to debug a program is by the Scientific Method
1. Define the problem (What is your bug?).
2. Collect information (Make sure all functions do what you think, watch variables).
3. Form a hypothesis (Propose a cause of the bug).
4. Test the hypothesis (Run the program with that factor different).
5. Make a conclusion (Figure out what's happening and how to fix it).
Don't bother communicating the results.

The text has been frozen!!!
Def Gie is offline   Reply With Quote
Old 04-07-2007, 08:19 PM   #5
JohnnyTightLips
Registered User
 
Join Date: Aug 2005
Posts: 87
Default

Thanks again Def, I used your help as a guide and found out the problems I had, but now a new one has come up which I didn't pay attention to before. This will be hard to explain so I posted me .fla.

My bullet works fine - you can shoot the proper way, you can't control it once it's left the starting coordinate, it dissaperas once it has reached a certain point. But now I have figured out, that when you move before you shoot, the bullet remains hidden. If you start my game by shooting, and then move to a new spot before the bullet dissapears, you will be able to shoot again. However, if you move after the bullet has dissapeared, or hasen't appeared at all for that matter, the bullet will remain hidden.

Does anyone know what the problem is?

Thanks in adavnce for any help - JohnnyTightLips

P.S. the .fla format is for Flash MX 2004, so if it won't run on your computer, send reply about this problem, and I will send another .fla in the format that will work for you.
JohnnyTightLips is offline   Reply With Quote
Old 04-07-2007, 08:20 PM   #6
JohnnyTightLips
Registered User
 
Join Date: Aug 2005
Posts: 87
Default

Here's the .fla. I forgot to put it on the other reply .
Attached Files
File Type: zip Side Scrolling Game.zip (5.9 KB, 121 views)
JohnnyTightLips is offline   Reply With Quote
Old 04-09-2007, 02:54 PM   #7
Def Gie
deaf guy
 
Def Gie's Avatar
 
Join Date: Jul 2006
Posts: 183
Default

Oh, yet again. The bullet gets placed at the current position of the man + 1, and stays there, besides when it is fired. Therefore the position test does not return true. If you test for its being invisible instead of in the right position (maybe I should have thought of this in the first place), and then set it to the right position, then it shouldn't have that problem.
Instead of
ActionScript Code:
if (Key.isDown(65) && (_root.bullet._x ==_root.man._x +1)) {
in the manner I first suggested
something more like
ActionScript Code:
if (Key.isDown(65) && (_root.bullet._visible == false)) {                 _root.bullet._x = _root.bullet._x + 1                 //other stuff
Thinking ahead a little, with this system you might have situations where enemies (or whatever you shoot) get hit by the invisible bullet. You should probably give it an underground _y coordinate while it's inactive and move it to the right _y when it gets fired.
__________________
The only way to debug a program is by the Scientific Method
1. Define the problem (What is your bug?).
2. Collect information (Make sure all functions do what you think, watch variables).
3. Form a hypothesis (Propose a cause of the bug).
4. Test the hypothesis (Run the program with that factor different).
5. Make a conclusion (Figure out what's happening and how to fix it).
Don't bother communicating the results.

The text has been frozen!!!
Def Gie is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with loading unloading clips and dynamic text sah302 ActionScript 1.0 (and below) 1 01-06-2006 05:19 PM
Shooting game problem Morret Gaming and Game Development 1 06-16-2005 04:11 AM
Flash Number type and c# float and decimal types. Convertion problem within Flash. maglez ActionScript 2.0 2 06-02-2005 05:14 PM
HEEELP!!! cant work out the answer to a problem case ActionScript 1.0 (and below) 1 07-29-2003 11:37 PM
global TextField Problem! Guru wonted mediaholic ActionScript 1.0 (and below) 3 07-20-2003 10:07 AM


All times are GMT. The time now is 11:52 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.