Movement

Ok… I have a simple code for movement…


on (keyPress "<Left>") {
	currentX = this._x;
	this._x = currentX - 2;
	_root.hansl_front._rotation = 270;
}
on (keyPress "<Right>") {
	currentX = this._x;
	this._x = currentX + 2;
	_root.hansl_front._rotation = 90;
}
on (keyPress "<Up>") {
	currentY = this._y;
	this._y = currentY - 2;
	_root.hansl_front._rotation = 360;
}
on (keyPress "<Down>") {
	currentY = this._y;
	this._y = currentY + 2;
	_root.hansl_front._rotation = 180;
}

I want it so that whenever you hit like the up button… it changes the movieclip to a differnt image so it looks like the character is actually walking forward backwards and ect…
thanks for your help

if you add another keyframe to your character mc…
put a stop on the first frame, then add something like this to your code:

[AS]
on (keyPress “<Left>”) {
currentX = this._x;
this._x = currentX - 2;
_root.hansl_front._rotation = 270;
_root.hansl_front.gotoAndPlay(2);
}
[/AS]

hmm that doesnt work… he still just walks up if i edit it to this


on (keyPress "<Up>") {
        currentX = this._y;
        this._y = currentX - 2;
        _root.hansl_front._rotation = 270;
        _root.hansl_front.gotoAndPlay(2);

}

?

Any Ideas?

thats the way its done :-\

wait… do i have to have the other image inside of the movie clip? like when you go to edit your movie clip… you put your new image in there?

yes. Instead of your movieclip being one static image, have it 2 frames. One of standing (frame 1), and one of walking (frame 2). Put a stop() on frame 1 so it starts standing. Then when the character moves, go to frame 2 so its walking. OF course with you’re current setup, moving on keypress like that, it might not work so well since you have no way to detect a return to the standing position - not easily at least. You might want to search the forums for movement with keys and look at alternative approaches (i.e. using onEnterFrame)

man i cant get this…

I have my movie clip on my regular layer… he has his actions… when I edit him he has two keyframes… one of him standing there and that action has
stop(); and right next to it is the other part of him so that it looks like hes actually walking… when I go to preview the scene it just makes him move upwards without changing the picture… :frowning:
character standing regular actionscript


on (keyPress "<Left>") {
        currentX = this._x;
        this._x = currentX - 2;
        _root.hansl_front._rotation = 270;
}

on (keyPress "<Right>") {
	currentX = this._x;
	this._x = currentX + 2;
	_root.hansl_front._rotation = 90;
}
on (keyPress "<Up>") {
        currentY = this._y;
        this._y = currentX - 2;
        _root.hansl_front.gotoAndPlay(2);

}

on (keyPress "<Down>") {
	currentY = this._y;
	this._y = currentY + 2;
	_root.hansl_front._rotation = 180;
}