ok im trying to make this link guy move w/ the animations i have when u press the right arrow key.let me show you how im trying to go about this:
(on an MC called "link")
on frame1 link is facing down(image)
on frame2 link is facing right(image)
on frame3 link is facing left(image)
on frame4 link is facing up(image)
on frame5 link is running down(an MC)
on frame6 link is running right(an MC)
on frame7 link is running left(an MC)
on frame8 link is running up(an MC)
all of the frame have "stop();" on them
i tried to do the keypress for going left like this:
it explains how you can set up your frames to get your directions going. The obstacles part you can pretty much ignore (unless you need it) and you can re-use your up or down clips in the angle directions if you dont have animations for them (or left and right for that matter).
i used the code from the .fla i got from GameDev and i made it match mine...here is the code im using:
Code:
onClipEvent (load) {
gotoAndStop(1);
var inc = 9;
var dir = "Right";
KeyListener = new Object();
KeyListener.onKeyUp = function() {
if (dir == "Down") {
gotoAndStop(1);
} else if (dir == "Right") {
gotoAndStop(2);
} else if (dir == "Up") {
gotoAndStop(4);
} else if (dir == "Left") {
gotoAndStop(3);
}
};
}
onClipEvent (enterFrame) {
Key.addListener(KeyListener);
if (Key.isDown(Key.LEFT)) {
dir = "Left";
this._x -= inc;
gotoAndStop(7);
} else if (Key.isDown(Key.RIGHT)) {
dir = "Right";
this._x += inc;
gotoAndStop(6);
} else if (Key.isDown(Key.UP)) {
dir = "Up";
this._y -= inc;
gotoAndStop(8);
} else if (Key.isDown(Key.DOWN)) {
dir = "Down";
this._y += inc;
gotoAndStop(5);
}
}
could someone explain some of it to me?
these in particular:
KeyListener(never seen anything like this before)
var dir(this either, how does it work?)
the use of "down", "up", "left", and "right".(are these constant?)
KeyListener(never seen anything like this before)
------------------------------------------------
this tracks your keypresses and waits to see when you release a key. So what I did was check to see when an arrow key was pressed (note its no key in specific, just any key released) then referenced the dir variable (left, right, down, up etc). So if the dir was set to "Right" for example then goto the stand right image when the walk right key is released.
var dir(this either, how does it work?)
------------------------------------------------
var just creates the dir (direction) variable so that I know what way he is walking when you release the key so that I can send you to the stop frame.
the use of "down", "up", "left", and "right".(are these constant?)
-------------------------------------------------------------------
there created strings in each direction so that the dir (direction) variable can report in which direction you are/ were walking.
Good luck,
Tyler
(making a zelda type game? want to look at my zelda clone?)
How expirienced w/ flash are you? Yeah, basically, but I have some updated code. I replaced the text in the variable dir for numbers. Saved me a lot of code. Anyway, you can have a variable be equal to anything, including strings ("text"). I'm getting pretty far on the clone, so when I have something worth testing ill let you know. Whats your email?