Basic Instant Replay in Flash Games
Instant Replays in flash games are quite rare but are easy to create. All you need to know is how to create and edit arrays, variable creation and editting, and basic if statements.
Arrays you need to create
1) Array for your character's X
2) Array for your character's Y
Here is the code I used to make this simple replay system: Replay Demo
//PLACE ALL THIS CODE INSIDE A SINGLE FRAMED MOVIE CLIP
//++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++
//CREATED BY IAN BROWN ON AUGUST 28, 2005
//THIS SCRIPT WAS MADE FOR 30 FPS.
//++++++++++++++++++++++++++++++++++++++
//CHANGE THESE VARIABLES
fps = 30;
//FRAMES PER SECOND
secondsToRecord = 2;
//HOW MANY SECONDS TO RECORD
//++++++++++++++++++++++++++++++++++++++
playbackArrayX = new Array();
//this is used to see how to move the players x
playbackArrayY = new Array();
//this is used to see how to move the players y
i = 0;
//sets the variable i to 0
j = 0;
//sets the variable j to 0
recording = false;
//sets variable recording to false
moved = false;
//setes variable moved to false
onEnterFrame = function () {
if (Key.isDown(Key.SPACE) && !recording) {
// Pressing Space will start the "recording" process
recording = true;
}
if (Key.isDown(Key.SHIFT) && recording) {
// Pressing Shift starts the "replay" process
playbackArrayX[i] = "EOF";
// creates an End Of File marker
recording = false;
moved = true;
_x = playbackArrayX[0];
// returns the characters _x to the starting position of the array
_y = playbackArrayY[0];
// returns the characters _y to the starting position of the array
}
if (recording) {
// if recording do this
if (Key.isDown(Key.LEFT)) {
// if Left Arrow is pressed
_x -= 1;
} else if (Key.isDown(Key.RIGHT)) {
// if Right Arrow is pressed
_x += 1;
}
if (Key.isDown(Key.UP)) {
// if Up Arrow is pressed
_y -= 1;
} else if (Key.isDown(Key.DOWN)) {
// if Down Arrow is pressed
_y += 1;
}
playbackArrayX[i] = _x;
playbackArrayY[i] = _y;
i++;
// adds 1 to the variable i
if (playbackArrayX.length>fps*secondsToRecord
) {
// if more than 2 seconds of actions are recorded remove the first element of the arrays
playbackArrayX.shift();
playbackArrayY.shift();
i--;
}
} else if (!recording && moved) {
// If no longer recording and the character has actually been moved
_x = playbackArrayX[j];
_y = playbackArrayY[j];
j++;
// adds 1 to variable j
if (playbackArrayX[j] == "EOF") {
// if the End Of File marker appears replay has ended and start over
_x = playbackArrayX[0];
_y = playbackArrayY[0];
j = 0;
}
}
};