more anim states?

4 posts

Flag Post

My guy code is coming along ok, He can walk, jump, and be still, on a slope, however I should like to be able to make him roll/duck and fight and run.
How can Incorporate more animation states in this code:

ps: thanks in advance!

onClipEvent (load) {
	speed = 3.6;
	Walkspeed = 0.7;
	gravity = 0;
	r = _height/19;
	jumping = false;
	rolling = false;
	var scale:Number = _xscale;
	jumpheight = 11;
	running = false;
	var touchingGround = false;
	scrolldistance = 2;
	moviewidth = Stage.width;
	movieheight = Stage.height;
	rightsensor = (moviewidth - ((moviewidth /1) * scrolldistance));
	leftsensor = ((moviewidth / 1) * scrolldistance);
	fg4 = speed * 1.4;
	fg3 = speed * 1.3;
	fg2 = speed * 1.2;
	fg1 = speed * 1.1;
	playerspd = speed;
	bg1 = speed * 0.2;
	bg2 = speed * 0.07;
	bg3 = speed * 2.2;
	bg4 = speed * 0.1;
	bg5 = speed * 1.4;
	bg6 = speed * 0.3;
	bg7 = speed * 4.2;
	bg8 = speed * 1.1;
	bg9 = speed * 2.1;
	bg10 = speed * 3.1;
	dbg = speed * 0.2;

}
onClipEvent (enterFrame) {
	if (Key.isDown(Key.RIGHT)) {
if (_x >= rightsensor) {
			_root.horse._x -= bg1;
			_root.ground._x -= bg1;
			_root.saddleStrap2._x -= bg1;
			_root.cup1._x -= bg1;
			_root.rocks._x -= bg3;
			_root.bgCopy._x -= bg4;
			_root.branch._x -= bg5;
			_root.fallenlogs._x -= bg6;
			_root.wizbg._x -= bg7;
			_root.wiztree._x -= bg8;
			_root.wizhouse._x -= bg9;
			_root.ground2._x -= bg10;
		}
	_xscale = +scale;
	if(touchingGround == true) {
	this.gotoAndPlay("walk");
	}
	_x += Walkspeed;
	} else if (Key.isDown(Key.LEFT)) {
	
if (_x <= leftsensor) {
			_root.horse._x += bg1;
			_root.ground._x += bg1;
			_root.saddleStrap2._x += bg1;
			_root.cup1._x += bg1;
			_root.rocks._x += bg3;
			_root.bgCopy._x += bg4;
			_root.branch._x += bg5;
			_root.fallenlogs._x += bg6;
			_root.wizbg._x += bg7;
			_root.wiztree._x += bg8;
			_root.wizhouse._x += bg9;
			_root.ground2._x += bg10;
			}
	_xscale = -scale;
	if(touchingGround == true) {
	this.gotoAndPlay("walk");
	}
	_x -= Walkspeed;
	} else {
	if (touchingGround == true) {
	this.gotoAndPlay("still");
	}
/////////////////////////////////////////////////////
	if(Key.isDown(Key.CONTROL)){
		touchingGround = true;
		gravity = 0;
		this.gotoAndPlay("roll");            < SOMETHING LIKE THIS !
		rolling = true;
		}else{
		rolling = false;
		}
//////////////////////////////////////////////////////
	}	
	if (Key.isDown(Key.UP) && !jumping) {
	gravity = -jumpheight;
	jumping = true;
	this.gotoAndStop("jump");
	}
	if (!_root.ground.hitTest(_x, _y, true)) {
	gravity++;
	_y += gravity;
	touchingGround = false;
	} else {
	jumping = false;
	gravity = 0;
	}
	while (_root.ground.hitTest(_x, _y-1+r, true)) {
	gravity = 0;
	jumping = false;
	_y--;
	touchingGround = true;
}
}
 
Flag Post

AS2 or AS3?

 
Flag Post
Originally posted by FlashGrenade:

AS2 or AS3?

AS2 of course, see how he handles events.

OP, you can draw more animations and handle them somewhere. Say a roll animation is finite, you develop that roll animation, and put a code in the last frame of rolling animation, triggering state check. Say a simple “rolling=false;” In enterframe handler you are checking “rolling” variable, if it’s true, you move your character along the ground, do not check for keys (as rolling is uninterruptible) and return, if false, you process as normal. Fighting (what’s fighting? Swinging a sword?) might be implemented similarly, but you might find out that you have to make more than one fighting animation. Charging, for example, is different from sword swinging.

 
Flag Post

thanks for the reply, they are AS2, can you help me incorporate any code, or I am not getting any where? thanks a lot for the advice I will try something in enterframe.