Hi, I know I'm new and what not and I know I'm not great with C or scripting. I do however read and get ideas and learn from reading other problems and solutions. I was working on this myself and have a working ged of this, though bear in mind the variables are differently named etc. I also used an already made sprite (just an easy way to test), the sprite will walk in all 4 directions (up, down, left, right) with changing animations, and has the wire-frame boxes to move the screen around when walking. I'm hopefully going to work on making an RPG type game... but anyway, you're welcome to it (hopefully to the other more knowledgeable it is up to snuff):
http://ifile.it/hr0ayxkEdit: The code I used....
I created 2 global variables: 'canmove' and 'inmotion'. As explained, using a number for each direction ( 1, 2, 3, 4 for down, right, left, up) and setting the direction number to 'inmotion' when in use. So when I press the 'down' key, 'inmotion' is set to 1. For any other direction key, if 'inmotion' is not equal to 0, it will not tell it to move.
On Key Down event:
- Code: Select all
if (canmove == 0 && inmotion == 0) {
yvelocity = 4;
inmotion = 1;
ChangeAnimation("Mog", "Mog - Walk (Front)", FORWARD);
}
Now, put the code for the key-up event; this is going to reset the 'inmotion' variable when you're finished pressing the 'down' key. Once you lift your finger off of the 'down' key, 'inmotion' is now set to 0. Now you can use another direction key.
On Key Up event:
- Code: Select all
if (inmotion == 1) {
yvelocity = 0;
inmotion = 0;
ChangeAnimation("Mog", "Mog (Front)", FORWARD);
}
Just remember, you have to create these events on each direction key. Make sure each key-down event has the appropriate key-up event (8 events total), you wouldn't want to have the 'right' key's key-up event on the 'left' key's key-up event, as you wouldn't be able to stop your character until you press and release the 'left' key. ^_~
I do not have the 'canmove' in the key up event, as it should be controlled by another event. Like talking with an NPC, have an event setting the 'canmove' variable to 1 or any other number, while you are talking to it. Once that event is finished, you should reset 'canmove' back to 0 to allow your character to move again. Sorry I didn't include any events that show this, in the ged file.
I hope that was clear and easy enough to unedrstand ^^;