I Want To Make A Character Move Up, Down, Left & Right By Using The Arrow Keys. When Moving, I Want The Character Do A Animation (walking) When You Stop, It Stops Moving. Also I Want To Make When A The Character Touches A Wall It Stop And Doesn’t Go Through… I Tried All This But It Didn’t Work And Someone Help Me?!
hm… what code have you got… and… you might wanna check www.FlashKit.com for that kinda stuff… they have lots of such examples on there
This wont work word for word but I hope it gives you enough of an idea how it would work.
onClipEvent (keyDown) {
if (Key.isDown(Key.UP)){
gotoAndPlay("characterMc","walkingUP");
// Example Movment from Sen's isometric stuff
_x += 20;
_y -= 10;
}else if (Key.isDown(Key.DOWN)){
gotoAndPlay("characterMc","walkingDN");
// Example Movment from Sen's isometric stuff
_x -= 20;
_y += 10;
}else if (Key.isDown(Key.LEFT)){
gotoAndPlay("characterMc","walkingLT");
// Example Movment from Sen's isometric stuff
_x -= 20;
_y -= 10;
}else if (Key.isDown(Key.RIGHT)){
gotoAndPlay("characterMc","walkingRT");
// Example Movment from Sen's isometric stuff
_x += 20;
_y += 10;
}
}
onClipEvent(keyUp) { // Assuming uses the same Key.is* formats
if (Key.isUp(Key.UP) &&
Key.isUp(Key.DOWN) &&
Key.isDown(Key.LEFT) &&
Key.isDown(Key.RIGHT)
) {
gotoAndPlay("characterMc","standing");
}
}
Roughly that should be what you would want to drop into the character’s MC… characterMc would be the instance name (I think?) of the clip. Since this is all within the clip you probally wouldnt need it. This is using Named Frames instead of numbers, I find it easier when doing different animation sets in a single movie clip like I do for a comic character I am working on.
You could improve this to check for diagonial movement, otherwise it will go in the order of the if statements…
As for the walking into a wall instead of through it, I’ve not gotten into object collison yet tho there is that hitTest function you could give a try… From the help files this is the Usage syntaxes.
myMovieClip.hitTest(x, y, shapeFlag)
myMovieClip.hitTest(target)
Idly thinking something like
onClipEvent (enterFrame) {
if(_root.characterMC, hittest(_root.wallMC)){
// reset characters position to not intersect the wall
}
}
Again I doubt any of this will work cut/paste wise, but it should atleast give ya the concepts on how to get what y want done…
Course I may just be an idiot and someone else will likely point that out too
(-: Right… wlel I won’t give you the exact code but it’ll look something like this algorithm…
if(LEFT KEY PRESSED)
{
for(x=0; x<numObjectsonScreen; x++)
{
if(!character does not hit one of the objects in the for loop)
{
character move left
character play inner animation
} else {
character stop playing inner animation
}
}
}
That isn’t exact code… But it’ll help you out… Just find the code that goes in there… I didn’t give you that cause you wouldn’t learn that way would you… If you need more help AFTER you tried it out again… Then just psot again with your new code you have. I’llt ake a look over it then.
try using enterFrame as your event handler instead of keyDown…