-
swashbuckling vector bandit
8 direction movement
Does anyone know the code for 8 direction movement with the arrow keys?
Steppenwolf is a good example of what i am trying to find. I have the code for 4 direction movement, but i cant seem to get the character to go diagonal.
Any help would be much appreciated
-Dave
-
you use && like you would do
if this && that
-
sorry, that was vague, i just didnt feel like thinking, there's a few things you can do, Im sure they talk about it in the game tutorial section here, check that out
Last edited by premiere522; 03-28-2004 at 12:52 PM.
-
Senior Member
Make movie clip and place this code on the movie clip:
Code:
onClipEvent (load) {
speed = 5;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT) and Key.isDown(Key.UP)) {
_x -= speed;
_y -= speed;
} else if (Key.isDown(Key.RIGHT) and Key.isDown(Key.UP)) {
_x += speed;
_y -= speed;
} else if (Key.isDown(Key.DOWN) and Key.isDown(Key.LEFT)) {
_x -= speed;
_y += speed;
} else if (Key.isDown(Key.DOWN) and Key.isDown(Key.RIGHT)) {
_x += speed;
_y += speed;
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
} else if (Key.isDown(Key.RIGHT)) {
_x += speed;
} else if (Key.isDown(Key.UP)) {
_y -= speed;
} else if (Key.isDown(Key.DOWN)) {
_y += speed;
}
}
-
swashbuckling vector bandit
Thanks Tonypa, that worked perfect, legend!
-Dave
-
swashbuckling vector bandit
One last thing, how can i get the characater to play the standing animation once the user has stopped moving, facing the way the user last pressed?
-Dave
-
Senior Member
Originally posted by beastyeast
One last thing, how can i get the characater to play the standing animation once the user has stopped moving, facing the way the user last pressed?
-Dave
This can be done by using separate frames for each direction in the hero movie clip. Lets say frame 1 for moving left, frame 2 for moving right... 8 frames total. In each frame place the movie clip with the correct animation for that movement and give that movie clip an instance name "hero".
Now when left key is pressed send movie clip to frame 1 and make animations play:
Code:
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
gotoAndStop (1);
this.hero.play();
}
same way for the right key:
Code:
}else if (Key.isDown(Key.RIGHT)) {
_x += speed;
gotoAndStop (2);
this.hero.play();
}
To make animation stop as soon as user has released the keys, send the animations movie clip to the frame 1 (which should have standing position).
Add in the end of code after last key detection:
Code:
} else {
this.hero.gotoAndStop(1);
}
Fla attached too with left/right animation.
-
swashbuckling vector bandit
Thanks again tonypa, worked brilliantly. Took me a while to get it working but its worked. Heres a little link to it working (tho i havent got the boundaries or the up animation done yet).
http://www33.brinkster.com/beastyeast/move_test.swf
Thanks again,
-Dave
-
That looks really amazing great potention.. is it just me or when you press up does he look like hes grabbin his crotch and sliding?
-
Senior Member
Lol, it so does
You're going to change the _xscale and _yscale too, right? Otherwise when he is close up he looks normal sized but when you go near the door he is a giant. Looks kinda wierd but you might be able to get away with it if you only have many small rooms like this.
-
Senior Member
Very nice animation
Could become great game.
I dont know if you should change the scale. For the example room it doesnt bother me, but if you create some street for example, going long way further, you might need to scale the char. If you do change the scale, make sure you place the registration point of the char movie clip in the bottom center, so his feet will stay on the ground.
-
swashbuckling vector bandit
aha, yeah when hes walking up he isnt animated yet, so just looks like hes sliding with some michael jackson pose.
I will definately have scaling. Might proove to be a pain as different scenes will need different scaling. Some scenes will require the character to scale quicker than others etc.
Im pretty new to coding, so i will be asking many a question here i am affraid. I dont even want to start thinking about coding the inventory items part yet.
-Dave
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|