Create Save Point


savepoint_result

Code

๐Ÿšซ

Donโ€™t forget to check Body in the objectโ€™s properties panel to use methods like onCollide!

snippet_physics-body Physics > Body

let startLocation = WORLD.getObject("StartLocation(aa3)");
 
function Start() {
  // 4 save points form spawn1 ~ spawn4
  for (let i = 1; i < 5; i++) {
    const point = WORLD.getObject("spawn" + i);
 
    point.onCollide(PLAYER, () => {
      startLocation = point;
    });
  }
}
 
function Update(dt) {
  //respawn when avatar y position is less than -5
  if (PLAYER.position.y < -5) {
    PLAYER.spawn(startLocation);
  }
}