Stay Updated!



Designed by:

XNA Tutorials
XNA Platformer Starter Kit - Checkpoint Tutorial
Written by Jeff Brown   

Adding checkpoints to Platform Starter Kit

Here's a video showing off the final product of this tutorial:


The way this works is by adding a tile to use in your text files and when you touch the tile it becomes your new respawn point. This works the same way as the checkpoints in the Sonic games.


In Tile.cs add the following in enum TileCollision:

Checkpoint = 3,

in Level.cs After this line:
private Vector2 start;
Add this:
public Vector2 checkpoint;


Now find the following:
public void StartNewLife() 
{
     Player.Reset(start); 
}

And change it to this:
public void StartNewLife()
{
     if(checkpoint != Vector2.Zero)
          Player.Reset(checkpoint);
     else
          Player.Reset(start);
}

In ‘private Tile LoadTile(...)’ add this near the others.
//Checkpoint
case 'P':
     return LoadTile("BlockA0", TileCollision.Checkpoint);

Now in Player.cs find the following:
TileCollision collision = Level.GetCollision(x, y);

And add this after it:
if (collision == TileCollision.Checkpoint)
   level.checkpoint = new Vector2(x, y) * Tile.Size;

 

Now make sure you add some 'P's to your levels so you can try out the checkpoints. Currently they just use the BlockA0 texture so you'll have to add your own to the Tiles folder and change the case 'P': ... texture argument to match your own checkpoint texture.
 

Add comment


Security code
Refresh