wise9/enchant.js

proper way to restart?

Closed this issue · 4 comments

i made litte game, and i was able to implement a restar by reloading the page as you can see here http://code.9leap.net/codes/show/60439 but i wonder if this would cause user to download again and it also gives me a delay, i so in the penguin game tutorial but i could not replicated, besides trying other solutions, i guess a way woud be doing scenes, a game over scenes, and a main game scene but it would seem for simple game, to be able to do it with just one scene. as always your help will be very apreciated tyvm

a buddy told me i could "renew" the game object but i could not figure out how to do it, but maybe best feature is just to reload page

what i did was restart variables and locations of sprites as when restarting the game and thi did te trick

Sorry to late response.
You can create the new scene that provides game rules on each restarting.
For example,

function createGameScene() {
    var scene = new Scene();
    // initialize the game character and rules.
    return scene;
}

// call when you need restarting
function restart(core) {
    core.replaceScene(createGameScene());
}

core.onload = function() {
    restart(this);
};

awesome that fells more efficient will try it, thank you very much :)