Here's a simple method that should work. You have a character that always runs in one direction. All you do is press and release a jump buton at the right time. You can add other keys, but for this example, I'll just use jump. The jump action is set up with a keyup and keydown event that changes a variable. The jump code is executed just by checking that variable (No other script on the events). This makes it simpler to do. You need an actor integer called 'time'. This will store the number of frames from the start. Create two arrays of long integers, one called 'rec', and one called 'read'. rec will be used to record the data you are currently playing. read will be used for the ghost actor to read from. You also need another actor integer called 'loc'. This will store the location in the array. You are using an actor variable calld 'jmp' to activate the jump key. A value of 1 means that the jump key is down, a value of 0 means it isn't. You'll also need another variable, 'stjmp', to store the initial position of the jump key. On your player's create actor, you need to initialize some vars:
- Code: Select all
jmp = getKeyState()[KEY_SPACE];
stjmp = jmp;
loc = 0;
time = 0;
On your draw actor script, you need to increment time:
- Code: Select all
time ++;
On your key down and key up events, add this script:
- Code: Select all
rec[loc] = time;
loc ++;
This sets the next position in the rec array to the current time, and advances the array location. When the game ends, you need to copy the rec array into the read array. I think you'll have to go through each slot with a 'for' loop (or is there a faster way?)
Now you need a 'ghost' actor. Set it up the same as your player, except without the keydown/up events. The create actor script should be changed to:
- Code: Select all
jmp = stjmp;
loc = 0;
time = 0;
On the draw actor script, you also need to add:
- Code: Select all
if (time == read[loc])
{
jmp = !jmp;
loc ++;
}
This checks if it is time to change the jmp variable, and if so, it chnges it, and adjustts loc to find the next slot. If you want to save your ghost, you need to put the variables read and stjmp in a save group, along with any other information.
I think this should do what you want. If you want more keys, it's probably easier to set up an array for each, although you might find a more efficient way using structs. I can't make a demo at the moment, because my GE computer is not set up, but if you have problems, just ask, and I or someone else should be able to help.