Be a Supporter!

Key.Down Animation Issue???

  • 381 Views
  • 9 Replies
New Topic Respond to this Topic
RemminyCricket
RemminyCricket
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Key.Down Animation Issue??? 2009-03-30 22:34:33 Reply

Ok so I posted this earlier but realized the link was dead and figured I shouldn't revive a dead post, so here I am with a new link.

Here is an FLA, the code is partly me but ultimately from disastamaans tutorial(on the kongregate website) for basic platforming. I'm just trying to learn right now(mostly from AS:Main, link me to other sites if you know any useful ones).

Download the FLA here

So I have a MC character and have him moving with the arrows. Now there are multiple(5) frames inside of this MC. Walk Animation(which is the first frame in the MC), Standing Animation, etc. So when I hit left arrow he walks and the walk animation cycles. BUT!!! When I crouch, etc. It doesn't loop the animation it just sits on a still image (as if I did not have an animation on that frame). What am I doing wrong?

DawnOfDusk
DawnOfDusk
  • Member since: Feb. 22, 2008
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-30 22:37:15 Reply

Check you crouching animation to see if there is a "stop();" on the first or second frame of that mini MC.

RemminyCricket
RemminyCricket
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-30 22:47:32 Reply

At 3/30/09 10:37 PM, DawnOfDusk wrote: Check you crouching animation to see if there is a "stop();" on the first or second frame of that mini MC.

Nope, I already tried this, but I just now tried it again to double check. I tried it within the crouching MC and also within the MC that contains all the MC, still no luck.

ZadeFireLance
ZadeFireLance
  • Member since: Oct. 10, 2008
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to Key.Down Animation Issue??? 2009-03-30 22:50:52 Reply

Did you try

onClipEvent (enterFrame) {
if (Key.isDown()) { // Keys
this._x = speed;
this.gotoAndStop(2);
}
onClipEvent (keyUp) { // Place this under Keys, however many you may have.
this.gotoAndStop(1);
}

like Dawn said put Stop(); on every action frame "Walk,Run,Jump" inside the mc.

RemminyCricket
RemminyCricket
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-30 22:59:07 Reply

Already tried putting stop on every frame, just the first, second, and third. I think I have a similar code...
Here is whats on my character:

onClipEvent (load) {
	var grav:Number = 0;
	// gravity
	var speed:Number = 10;
	// how fast you walk
	var jumpHeight:Number = 15;
	// how high you jump
	var slow:Number = .7;
	// sets water falling speed
	var slowspd:Number = speed/1.5;
	// sets water walking speed
	var setspeed:Number = speed;
	var scale:Number = _xscale;
	var ex:Number = 5;
	// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
	this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
	grav++;
	_y += grav;
	while (_root.ground.hitTest(_x, _y, true)) {
		_y--;
		grav = 0;
	}
	if (_root.water.hitTest(_x, _y, true)) {
		if (grav>0) {
			grav *= slow;
		}
		speed = slowspd;
	} else {
		speed = setspeed;
	}
	if (Key.isDown(Key.RIGHT)) {
		_x += speed;
		_xscale = scale;
		if (_root.ground.hitTest(_x, _y+3, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else if (Key.isDown(Key.LEFT)) {
		_x -= speed;
		_xscale = -scale;
		if (_root.ground.hitTest(_x, _y+3, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else {
		if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
			this.gotoAndStop(3);
		}
	}
	if (Key.isDown(Key.DOWN) && !Key.isDown(Key.UP) && Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT)) {
		this.gotoAndStop(5);
			}
	if (Key.isDown(73) && !Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(79)) {
		this.gotoAndStop(4);
	}
	if (Key.isDown(Key.UP) && _root.ground.hitTest(_x, _y+3, true)) {
		grav = -jumpHeight;
		_y -= 4;
		this.gotoAndStop(2);
	}
	if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
		_x -= speed;
	}
	if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
		_x += speed;
	}
	if (_root.ground.hitTest(_x, _y-_height-15, true)) {
		grav = 1;
	}
}
ZadeFireLance
ZadeFireLance
  • Member since: Oct. 10, 2008
  • Offline.
Forum Stats
Member
Level 12
Programmer
Response to Key.Down Animation Issue??? 2009-03-30 23:34:07 Reply

try placing it like this, it should work with your code.

if (_root.ground.hitTest(_x, _y-_height-15, true)) {
		grav = 1;
	}
}
onClipEvent(keyUp){
this.gotoAndStop(1);
}

keyUp is when any key is not touched/down, not to be confused with Key.UP which is the up arrow of course :P

any further bugs show up, keep posting and im sure your answer will come. :D

RemminyCricket
RemminyCricket
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-30 23:56:33 Reply

At 3/30/09 11:34 PM, ZadeFireLance wrote: try placing it like this, it should work with your code.

if (_root.ground.hitTest(_x, _y-_height-15, true)) {
grav = 1;
}
}
onClipEvent(keyUp){
this.gotoAndStop(1);
}

Sorry to be a complete noob, but where exactly do I insert this code?

JnDproductions2008
JnDproductions2008
  • Member since: Mar. 16, 2009
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-31 00:52:08 Reply

you put the stop thing in the frame and actionscript in the movie clip

RemminyCricket
RemminyCricket
  • Member since: Mar. 27, 2009
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-31 02:50:32 Reply

At 3/31/09 12:52 AM, JnDproductions2008 wrote: you put the stop thing in the frame and actionscript in the movie clip

Haha my bad, I meant where in my script specifically to I place that, I know it goes on the MC, I shouldve been more specific.

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Key.Down Animation Issue??? 2009-03-31 08:24:04 Reply

Basically the reason you're not seeing the animation is because the MC playhead is being sent to frame 4/5 on every enterFrame, so all you'll see is the first frame of the animation since it gets reset every time the code runs.

This is complicated, because the enterFrame has so many Key.isDown checks, but basically you need to set a boolean (true/false or 1/0) crouched and only run the gotoAndPlay(4/5) if NOT crouched already. Unfortunately as I said, you have so many keychecks already, I don't have time to fix it perfectly, but hopefully this'll help you in the right direction.

onClipEvent (load) {
	var crouched=0;
	var grav:Number = 0;
	// gravity
	var speed:Number = 10;
	// how fast you walk
	var jumpHeight:Number = 15;
	// how high you jump
	var slow:Number = .7;
	// sets water falling speed
	var slowspd:Number = speed/1.5;
	// sets water walking speed
	var setspeed:Number = speed;
	var scale:Number = _xscale;
	var ex:Number = 5;
	// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
	this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
	grav++;
	_y += grav;
	while (_root.ground.hitTest(_x, _y, true)) {
		_y--;
		grav = 0;
	}
	if (_root.water.hitTest(_x, _y, true)) {
		if (grav>0) {
			grav *= slow;
		}
		speed = slowspd;
	} else {
		speed = setspeed;
	}
	if (Key.isDown(Key.RIGHT)) {
		_x += speed;
		_xscale = scale;
		if (_root.ground.hitTest(_x, _y+3, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else if (Key.isDown(Key.LEFT)) {
		_x -= speed;
		_xscale = -scale;
		if (_root.ground.hitTest(_x, _y+3, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else {
		if (!crouched && _root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
			this.gotoAndStop(3);
		}
	}
	if(Key.isDown(Key.DOWN)){
		if (!crouched && !Key.isDown(Key.UP) && Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(73)) {
			this.gotoAndStop(5);
		}
		if (!crouched && !Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && Key.isDown(Key.RIGHT) && !Key.isDown(73)) {
			this.gotoAndStop(5);
		}
		if (!crouched && !Key.isDown(Key.UP) && !Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(79)) {
			this.gotoAndStop(4);
		}
		crouched=1;
	}else{
		crouched=0;
	}
	if (!crouched && Key.isDown(Key.UP) && _root.ground.hitTest(_x, _y+3, true)) {
		grav = -jumpHeight;
		_y -= 4;
		this.gotoAndStop(2);
	}
	if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
		_x -= speed;
	}
	if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
		_x += speed;
	}
	if (_root.ground.hitTest(_x, _y-_height-15, true)) {
		grav = 1;
	}
}

- - Flash - Music - Images - -

BBS Signature