Hey everyone!
For the past couple of days I have been looking into saving replays done in Flixel, but this method can be done in any fashion to record data about a play-through. Luckily, Flixel has a handy debugging tool, which includes capturing.
To start capturing at anytime, just run FlxG.recordReplay(). This will reset the game, and start recording. A nice place to put this is right below the call to the super constructor in your Main script.
Next, in FlxGame, add a public variable int, which is set in the FlxGame constructor to be random. I used Math.floor(Math.random()_(int.MAX_VALUE)).
Go over to FlxG, and make a new method:
static public function uploadRecording():void
{
var vars:URLVariables = new URLVariables();
vars.user = _game.identifier;
vars.replay = _game._replay.save(); // This returns the current replay in string format!
var request:URLRequest = new URLRequest(/_Where you host your php script*/);
request.method = URLRequestMethod.POST;
request.data = vars;
var loader:URLLoader = new URLLoader();
loader.load(request);
}
As mentioned in the code above, you need a php file to actually save the data!
<?php
if (isset($_POST['user']) && isset($_POST['replay'])) {
file_put_contents("writeable/replays/" . $_POST['user'] . ".fgr", $_POST['replay']);
} else {
print "no";
}
?>
This saves the replay to a folder called replays, inside of writeable, with the file name of user, or the identifier we passed in earlier.
To actually be able to write to a file, however, we need to do something weird with file permissions.
First, make a folder in your www/ directory with permissions of 755.
Next, go into that folder, and make another folder with permissions of 753, this is the folder you want to write too.
Finally, make sure it works, and you are good to go!
Whenever you want to upload a replay, just call FlxG.uploadRecording(), and it will overwrite the previous replay that was uploaded in that play session. I am planning on uploading a recording every minute or so.
There are other ways to do analytics like this, but replaying a game (especially since Flixel already provides a nice interface for it) can be very valuable to see. Just be sure to take the recording out once you actually ship the game, as it will put quite a strain on the cs network.
If you have any questions, feel free to ask me!
Chris
From that email:
Hey everyone! For the past couple of days I have been looking into saving replays done in Flixel, but this method can be done in any fashion to record data about a play-through. Luckily, Flixel has a handy debugging tool, which includes capturing. To start capturing at anytime, just run FlxG.recordReplay(). This will reset the game, and start recording. A nice place to put this is right below the call to the super constructor in your Main script. Next, in FlxGame, add a public variable int, which is set in the FlxGame constructor to be random. I used Math.floor(Math.random()_(int.MAX_VALUE)). Go over to FlxG, and make a new method: static public function uploadRecording():void { var vars:URLVariables = new URLVariables(); vars.user = _game.identifier; vars.replay = _game._replay.save(); // This returns the current replay in string format! var request:URLRequest = new URLRequest(/_Where you host your php script*/); request.method = URLRequestMethod.POST; request.data = vars; var loader:URLLoader = new URLLoader(); loader.load(request); } As mentioned in the code above, you need a php file to actually save the data! <?php if (isset($_POST['user']) && isset($_POST['replay'])) { file_put_contents("writeable/replays/" . $_POST['user'] . ".fgr", $_POST['replay']); } else { print "no"; } ?> This saves the replay to a folder called replays, inside of writeable, with the file name of user, or the identifier we passed in earlier. To actually be able to write to a file, however, we need to do something weird with file permissions. First, make a folder in your www/ directory with permissions of 755. Next, go into that folder, and make another folder with permissions of 753, this is the folder you want to write too. Finally, make sure it works, and you are good to go! Whenever you want to upload a replay, just call FlxG.uploadRecording(), and it will overwrite the previous replay that was uploaded in that play session. I am planning on uploading a recording every minute or so. There are other ways to do analytics like this, but replaying a game (especially since Flixel already provides a nice interface for it) can be very valuable to see. Just be sure to take the recording out once you actually ship the game, as it will put quite a strain on the cs network. If you have any questions, feel free to ask me! Chris