mirror of
https://github.com/danbulant/heaventaker
synced 2026-07-08 04:30:36 +00:00
map switching
This commit is contained in:
parent
f4b51f6264
commit
b56c53b025
2 changed files with 22 additions and 1 deletions
|
|
@ -32,6 +32,14 @@ export class GameScene extends Phaser.Scene {
|
||||||
steps.set(map.steps);
|
steps.set(map.steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unload() {
|
||||||
|
this.grid.destroy();
|
||||||
|
this.background.destroy();
|
||||||
|
this.container.destroy();
|
||||||
|
delete this.items;
|
||||||
|
delete this.winds;
|
||||||
|
}
|
||||||
|
|
||||||
preload() {
|
preload() {
|
||||||
this.load.setBaseURL();
|
this.load.setBaseURL();
|
||||||
this.load.image("level1", "/sprite/level1.webp");
|
this.load.image("level1", "/sprite/level1.webp");
|
||||||
|
|
@ -49,6 +57,10 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.game.sound.context.resume();
|
this.game.sound.context.resume();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.createMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
createMap() {
|
||||||
console.log(this.map);
|
console.log(this.map);
|
||||||
|
|
||||||
this.container = this.add.container();
|
this.container = this.add.container();
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,12 @@ export function resize() {
|
||||||
var htmlcanvas;
|
var htmlcanvas;
|
||||||
/** @type {Game} */
|
/** @type {Game} */
|
||||||
var game;
|
var game;
|
||||||
|
/** @type {GameScene} */
|
||||||
|
var gs;
|
||||||
export function setCanvas(canvas) {
|
export function setCanvas(canvas) {
|
||||||
htmlcanvas = canvas;
|
htmlcanvas = canvas;
|
||||||
var ctx = canvas.getContext("webgl2") || canvas.getContext("webgl");
|
var ctx = canvas.getContext("webgl2") || canvas.getContext("webgl");
|
||||||
|
gs = new GameScene(map);
|
||||||
game = new Game({
|
game = new Game({
|
||||||
canvas: canvas,
|
canvas: canvas,
|
||||||
url: window.location.host,
|
url: window.location.host,
|
||||||
|
|
@ -29,7 +32,7 @@ export function setCanvas(canvas) {
|
||||||
},
|
},
|
||||||
title: "Heaventaker",
|
title: "Heaventaker",
|
||||||
version: "beta",
|
version: "beta",
|
||||||
scene: [new GameScene(map)],
|
scene: [gs],
|
||||||
backgroundColor: "#01021B"
|
backgroundColor: "#01021B"
|
||||||
});
|
});
|
||||||
game.hideBanner = true;
|
game.hideBanner = true;
|
||||||
|
|
@ -45,4 +48,10 @@ var mapname;
|
||||||
export function setMap(newmap) {
|
export function setMap(newmap) {
|
||||||
mapname = newmap;
|
mapname = newmap;
|
||||||
map = maps[mapname];
|
map = maps[mapname];
|
||||||
|
if(gs) {
|
||||||
|
gs.unload();
|
||||||
|
gs.map = map;
|
||||||
|
gs.createMap();
|
||||||
|
}
|
||||||
|
console.log("Loaded map", mapname);
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue