i have only just started, could someone give me some code to make one stickman move left and right, i have walking and still animations, just need the code, i’ve tried to code it myself but it failed my attemp at code was this -
stop();
function moveStickman(){}
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;
} else if (Key.isDown(Key.LEFT)) {
dx = -10;
} else {
// no movement
dx = 0;
}
// move the stickman and limit that movement
stickman._x += dx;
if (stickman._x < 30) stickman._x = 30;
if (stickman._x > 520) stickman._x = 520;
// make the stickman run or stand still
if ((dx != 0) and (stickman._currentFrame == 1)) {
stickman.gotoAndPlay("stickman");
} else if ((dx == 0) and (stickman._currentFrame != 1)) {
stickman.gotoAndPlay("stickmanstill");
}
does anyone knoe the code to make it work coz i’m a real newbie with actionscript and i really need to get this dun, otherewise could someone tell me a link to a site which has a tutorial on it for this sort of thing?
:pirate:
One thing I noticed: you attached the stickman clip under the name stickmanstill, so that’s how you have to call it when you want to move it. Not just stickman.
my problem is that for some reason when i export the movie all i see is my motion stickman walkng while staying still in the very top left corner. n e ideas? just trying it again give me a sec …
the function declaration… arent the curley brackets supposed to be open here and closed after all the code for that function has been written?? so it would be
function moveStickman(){
code
}
cuz it seems like the function wont do anything when called… if there is no code in it… but im not too hot on functions in flash so im probably wrong
}
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;
} else if (Key.isDown(Key.LEFT)) {
dx = -10;
} else {
// no movement
dx = 0;
}
// move the stickman and limit that movement
stickmanstill._x += dx;
if (stickmanstill._x < 30) stickmanstill._x = 30;
if (stickmanstill._x > 520) stickmanstill._x = 520;
// make the stickman run or stand still
if ((dx != 0) and (stickmanstill._currentFrame == 1)) {
stickmanstill.gotoAndPlay("stickman");
} else if ((dx == 0) and (stickmanstill._currentFrame != 1)) {
stickmanstill.gotoAndPlay("stickmanstill");
}
this is the code i have got from your help, i would greatly appreciate it if you could tell me what I need to change and why, sorry for being such a pain.[SIZE=1]stop();[/SIZE] [FONT=arial]stop();[/FONT] [FONT=arial]stop();[/FONT]
stop();
function initGame() {
// create the stickman
attachMovie( "stickman", "stickmanstill",20) ;
stickman._x = 275;
stickman._y = 300;
}
function movestickman() {
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;
} else if (Key.isDown(Key.LEFT)) {
dx = -10;
} else {
// no movement
dx = 0;
}
// move the stickman and limit that movement
stickmanstill._x += dx;
if (stickmanstill._x < 30) stickmanstill._x = 30;
if (stickmanstill._x > 520) stickmanstill._x = 520;
// make the stickman run or stand still
if ((dx != 0) and (stickmanstill._currentFrame == 1)) {
stickmanstill.gotoAndPlay("stickman");
} else if ((dx == 0) and (stickmanstill._currentFrame != 1)) {
stickmanstill.gotoAndPlay("stickmanstill");
}
}
thanx for the code it works now, but one minor problem the stickman starts at the top of the screen and even when i change the “y” properties it won’t move down, could you tell me how i can make it move please?