00:00
00:00
Newgrounds Background Image Theme

Ryor just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS help! 2006-08-05 13:58:32


Hi everyone, I got a problem and would really appreciate some help...

I've been trying to code a sidescrolling shooter, much like Metal Slug. Progress has been going relatively well, but I've run into some problems...

I can't get the "shooting in four directions" bit right.
Here's the code:

if (Key.isDown(Key.UP) && (Key.isDown((88)))) {
gotoAndStop(5)
//This plays the shooting UP animation.
}
if (Key.isDown(Key.DOWN) && (Key.isDown((88)))) {
gotoAndStop(6);
//This plays the shooting DOWN animation.
}

The code makes it so you have to HOLD the UP key and the X key to shoot up, and the DOWN key and the X key to shoot down.

Now that actually does work, problem is, when it goes to the frame in the Hero MC that plays the shooting animation, it doesn't play the MC on that frame when both keys are held down! It simply stays stuck on the first frame of the animation. However, if you release both keys at the same time it plays the shooting animation on that frame. I just don't know how to fix it.. I've looked everywhere; AS: Main, Google, Flashkit, and have turned up with no remedy for this problem. If someone could lend me a hand with the code, or point me in the direction of a tutorial that would suit my needs, I'd be very thankful.

Response to AS help! 2006-08-05 14:06:00


if (Key.isDown(Key.UP) && (Key.isDown((88))) && this._currentframe != 5) {
gotoAndStop(5);
//This plays the shooting UP animation.
} else if (Key.isDown(Key.DOWN) && (Key.isDown((88))) && this._currentframe != 6) {
gotoAndStop(6);
//This plays the shooting DOWN animation.
}

Detect the _currentframe property on your clip, to make sure you are not running the code while the clip is already on the 5th or 6th frame.


Hi there!

BBS Signature

Response to AS help! 2006-08-05 14:13:55


Detect the _currentframe property on your clip, to make sure you are not running the code while the clip is already on the 5th or 6th frame.

How do I detect the _currentframe property?

Response to AS help! 2006-08-05 14:20:52


At 8/5/06 02:13 PM, VVithereD wrote: How do I detect the _currentframe property?

That code already has it in there, you may have to tweak a few things though...

Pretty much, you are just setting up an if statement.

if() {
//do this
}

So when you say something like this...
if(this._currentframe == 5) {
//do this
}

...you are really saying "if the current frame of this movie clip is 5, perform the action".


Hi there!

BBS Signature

Response to AS help! 2006-08-05 14:40:44


Still no luck :/

Response to AS help! 2006-08-05 15:15:14


The problem is exactly the same as a problem posted yesterday, except you're handling the situation much more calmly than that poster was.

What's happening is that you're telling the player clip to go to and play the shooting animation every frame. The problem is that since you're telling it to do that EVERY frame, it goes to the start of the animation EVERY frame. What you need to do is add another variable called something like "idle". Then, make the code work like this.

if(player.idle) {
if(Key.isDown(Key.UP) && Key.isDown(Key.88)){
gotoAndPlay(Whatever frame the shooting animation is);
player.idle = false;
}
//Repeat for all directions
}

Then, at the last frame of each shooting animation, put a keyframe on the actions layer with the line idle = true;

This makes sure that it won't go to the firing animation every frame. It'll go to it, play it once, and then check key presses again.

Giving people code is like giving them crack, it only solves the immediate problem. Say thank you to the drug dealer.

Response to AS help! 2006-08-05 16:34:00


At 8/5/06 03:15 PM, Fat_Lifeguard wrote: The problem is exactly the same as a problem posted yesterday, except you're handling the situation much more calmly than that poster was.

What's happening is that you're telling the player clip to go to and play the shooting animation every frame. The problem is that since you're telling it to do that EVERY frame, it goes to the start of the animation EVERY frame. What you need to do is add another variable called something like "idle". Then, make the code work like this.

if(player.idle) {
if(Key.isDown(Key.UP) && Key.isDown(Key.88)){
gotoAndPlay(Whatever frame the shooting animation is);
player.idle = false;
}
//Repeat for all directions
}

Then, at the last frame of each shooting animation, put a keyframe on the actions layer with the line idle = true;

This makes sure that it won't go to the firing animation every frame. It'll go to it, play it once, and then check key presses again.

Giving people code is like giving them crack, it only solves the immediate problem. Say thank you to the drug dealer.

Alright, I attempted to make a variable called Idle, which would look like this;

onClipEvent(load){
Idle = true;

Right? Do I have to name the "standing still frame" idle?
(If you could not already tell, I'm new to AS.)

I followed your instructions but to no avail, it flopped. The "firing frame" now only shows the first frame of the animation VERY quickly, then reverts back to the "standing" frame of the animation. It doesn't do this every time you press the keys either, when you press X+UP/DOWN it doesn't play anything most of the time and stays on the standing still frame....but some times when you press the keys it will do what I previously stated. Thanks to those who helped me so far by the way.

Response to AS help! 2006-08-05 18:13:30


Nobody?