Skip to content

Commit

Permalink
Remove workaround from issue #1
Browse files Browse the repository at this point in the history
We can load spritesheets and their normal maps at once again thanks to fix in phaser 3.70.0
  • Loading branch information
PaulB-H committed Dec 5, 2023
1 parent c4ffd68 commit 92b3135
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 53 deletions.
18 changes: 0 additions & 18 deletions src/scenes/BaseScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,6 @@ export default class BaseScene extends Phaser.Scene {
this.registry.set("pausedSceneKey", this.scene.key);
});

// Emergency workaround to fix missing frame
// https://github.com/PaulB-H/breakout/issues/1
if (this.textures.get(SHEETS.Tiles).frameTotal < 101) {
console.log(
`ERR
Spritesheet should have 101 frames but only has: ${
this.textures.get(SHEETS.Tiles).frameTotal
}
Reloading page...`
);

// Removing cache and re-running preloader didn't
// resolve, but I like the idea of this over a page reload...
// this.cache.destroy();
// this.scene.start("PreloaderScene");

location.reload();
}
/*
_Contents
Expand Down
48 changes: 13 additions & 35 deletions src/scenes/PreloaderScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,21 @@ export default class PreloaderScene extends Phaser.Scene {
}

preload() {
// // "tiles"
// this.load.spritesheet({
// key: SHEETS.Tiles,
// url: "assets/main-tileset/breakout-extruded.png",
// normalMap: "assets/main-tileset/breakout-extruded_n.png",
// frameConfig: {
// frameWidth: 16,
// frameHeight: 16,
// spacing: 2,
// margin: 1,
// startFrame: 0,
// endFrame: 99,
// },
// });

this.load.image(
"breakout-extruded_n",
"assets/main-tileset/breakout-extruded_n.png"
);
this.load.spritesheet(
SHEETS.Tiles,
"assets/main-tileset/breakout-extruded.png",
{ frameWidth: 16, frameHeight: 16, margin: 1, spacing: 2 }
);
this.load.once("complete", function (loader: Phaser.Loader.LoaderPlugin) {
const sheet = loader.textureManager.get(SHEETS.Tiles);
const normalMap = loader.textureManager.get("breakout-extruded_n");
const normalMapSrcImg = normalMap.getSourceImage();

if (
normalMapSrcImg instanceof HTMLImageElement ||
normalMapSrcImg instanceof HTMLCanvasElement
) {
sheet.setDataSource(normalMapSrcImg);
}
// SHEETS.Tiles
this.load.spritesheet({
key: SHEETS.Tiles,
url: "assets/main-tileset/breakout-extruded.png",
normalMap: "assets/main-tileset/breakout-extruded_n.png",
frameConfig: {
frameWidth: 16,
frameHeight: 16,
spacing: 2,
margin: 1,
},
});

///////////////////
// Load Tilemaps
// prettier-ignore
{
this.load.tilemapTiledJSON(SCENES.DemoScene, "assets/levels/breakout.json");
Expand Down

0 comments on commit 92b3135

Please sign in to comment.