Well, I was told to make this tutorial..I'm not a good tutor anyway, but I'll try...
The System
The system is you will save your current location, defined by the x and y axis into variables, then you can save that variables into file. For example your save file will be "data.sav". In this system, you have Actors called "Player" as your main player, and "Checkpoint" as the checkpoint actor. Well, the you can use some flag sprite as the checkpoint actor.
Requirements
The requirement is only 2 variables. "PosX" - to define the x position, and "PosY" to define the y position. To make the variable, go to the Script Editor or Global code, then click "Variables" button bellow the window.
You need to make the Save group in order to save them into file.
The Script
Here's the scripting step...
1. First, we want to save the current location when the Player colliding with the Checkpoint flag. So, we need to put this code on...
Player -> Collision -> Anyside of Checkpoint -> Script Editor :
- Code: Select all
PosX = x; //store the x position
PosY = y; //store the y position
saveVars("data.sav", "data"); //save the data into file "data.sav"
2. Then, we want if the player die, he will load his latest checkpoint location. In this case, the Player dying with DestroyActor, so on...
Player -> Destroy Actor -> Script Editor :
- Code: Select all
CreateActor("Player", "PlayerAnimation", "(none)", "(none)", PosX, PosY, true); //create player to the latest checkpoint location
view.x=PosX-320; //set the view x position
view.y=PosY-240; //set the view y position
We need to set the view position in order for the camera will follow the Player.
3. The last is, when next time we play the game again, and want to load the latest checkpoint... So, on...
Player -> Create Actor -> Script Editor :
- Code: Select all
loadVars("data.sav", "data"); //load your saved data from file
x=PosX; //set the x position
y=PosY; //set the y position
view.x=PosX-320; //set the view x position
view.y=PosY-240; //set the view y position
Please Note
Whenever we change the Player's location, don't forget to move the view's location as well. Or else, the camera won't follow you.
Hope helps, and thanks