I have a Flash AS 3.0 swf-based browser game. It's hosted on my site and communicates with a MySQL database via PHP using Flash's URLVariables. Everything works fine. The problem is, I want to be able to save the player's game after he leaves the webpage or closes his browser. How is this usually handled?
Is there a reliable eve开发者_StackOverflow中文版nt that fires when a swf is terminated? Is so, what is it? If not, what's the solution? Should I simply save the player's data every x seconds? That seems like it will bog down my server. I could have 10,000 people playing and I don't want to save each of their games every x seconds.
There is no such event and you should solve this problem with clever UI and in-game tutorial which includes manual saving instructions. You can also try to automatically save the game only after the critical game moments.
The actual solution depends on the type of the game you make. For usual solutions take a look at the games matching the genre of your game on the http://kongregate.com
Save your game after your player has done something.
Did the player upgrade their tower to level 2? Save data.
Did the player attack a boat? Save data.
If you do that, you have nothing to worry about when the user exits the page.
Your SWF should just be a client that displays that and allows players to select choices - do not put any game play logic* inside it unless you want it to get hacked with cheat engine in 3 seconds.
By that, I mean, don't go
if(playerResources > 500){
build();
}
Rather
if(server.build() == 1){
server.getUpdatedBuildings();
} else {
notifyUser("Not enough resources!");
}
Never ever trust the client.
精彩评论