Fixed an issue with the stats when level switching
This commit is contained in:
parent
a57dab97ce
commit
0b508af1df
16
src/game.js
16
src/game.js
@ -27,7 +27,7 @@ player.pos.y = level.startPos[0].y / 1;
|
||||
player.level = level;
|
||||
|
||||
const camera = new Camera(player, window, { w: level.w * 2, h: level.h * 2 });
|
||||
const stats = new Stats(player);
|
||||
var stats = new Stats(player);
|
||||
|
||||
scene.add(camera);
|
||||
camera.add(level);
|
||||
@ -35,21 +35,33 @@ camera.add(player);
|
||||
scene.add(stats);
|
||||
|
||||
function switchLevel(module, pos = 0) {
|
||||
scene.remove(stats);
|
||||
console.log(scene);
|
||||
camera.map(function(e) {
|
||||
camera.remove(e);
|
||||
if (e instanceof Level) {
|
||||
var lives = player.lives;
|
||||
var items = player.items;
|
||||
player = new Player(keys, window);
|
||||
|
||||
var p = new Player(keys, window);
|
||||
player = p;
|
||||
|
||||
e = new Level(module, keys, player);
|
||||
level = e;
|
||||
|
||||
player.pos.x = level.startPos[pos].x / 1;
|
||||
player.pos.y = level.startPos[pos].y / 1;
|
||||
|
||||
player.lives = lives;
|
||||
player.items = items;
|
||||
player.level = e;
|
||||
|
||||
stats = new Stats(player);
|
||||
|
||||
camera.add(e);
|
||||
camera.add(player);
|
||||
camera.setSubject(player);
|
||||
scene.add(stats);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user