Hey,
So I may have a little trouble explaining this so please bare with me. I have a property bound to 'this' called tiles and when the game starts I load it up the following way. This tiles property is used to setup and mantain state of the board.
var self = this;
wade.loadScene('scene2.wsc', false, function () {
wade.loadJson(tilesFile, data, function () {
self.tiles = data.data.tiles;
//More Code here
});
});
And after fetching so, I use self.tiles to manipulate the board. So on the first gameplay it works fine.
Trouble arises when I move from one scene to another and also while reloading the same scene. So onclick of a button I load different scenes.
I do this by first clearning the scene then re-declare all values to origninal state like this.
this.startGame = function () {
var data = {};
var tilesFile = 'tiles.json';
self.bluePawnsTiles = [1, 3, 5, 7, 8, 10, 12, 14, 17, 19, 21, 23];
self.redPawnsTiles = [40, 42, 44, 46, 49, 51, 53, 55, 56, 58, 60, 62];
self.drag = false;
self.turn = 'red';
self.direction = null;
self.clickedTileObj = null;
self.pawnNum = null;
self.outOfBoundMove = false;
self.invalidMove = false;
wade.clearScene();
wade.loadScene('scene2.wsc', false, function () {
wade.loadJson(tilesFile, data, function () {
self.tiles = data.data.tiles;
//Run the game from here on
//More code
});
});
};
But the second time around, self.tiles still points to the old state, that is, the previous game state before loading new scene in the startGame function.
I set all properties to null and even set self.tiles to null. But I still have the same self.tiles as the previous session.
I tried wade.preloadJSON() as well but it is still no solution.
So basically my question is I want self.tiles to be reset to the original state as written in the tiles.json file and how it worked during the first gameplay.
Instead I end up with self.tiles still carrying the previous game state. Here is my tiles.json file.
{
"tiles": [
{
"tileNo": 0,
"x": -225,
"y": -245,
"occupiedBy": "none",
"pawn": "none"
},
{
"tileNo": 1,
"x": -160,
"y": -245,
"occupiedBy": "blue",
"pawn": "BluePawn0"
},
{
"tileNo": 2,
"x": -95,
"y": -245,
"occupiedBy": "none",
"pawn": "none"
},
//More objects
//More objects
//More objects
{
"tileNo": 62,
"x": 165,
"y": 215,
"occupiedBy": "red",
"pawn": "RedPawn11"
},
{
"tileNo": 63,
"x": 225,
"y": 215,
"occupiedBy": "none",
"pawn": "none"
}
]
}
Any help would be really appreciated... Thanks!