Hello,
I've been kind of fiddling with this for a couple of days. I'm trying to wrap gs.Tilemap as a component, but I'm having a hard time as it doesn't appear to be managed by the scene, and the tilemap simply appears everywhere, across scenes, on top of backgrounds, etc. After it gets created, it permanently exists.
My goal here was to create an extension that added a command to start a minigame involving tilemaps, while still using the visual VN maker portion for everything else.
I think the root of the problem lies in the dispose method. After disposing of the tilemap, It looks like it tries to render it still, and runs into problems because disposing of the tilemap disposes of the tileset bitmap.
I'll give an example, given the following Component_Tilemap:
and a custom ResourceLoader:
and the following scene:
You get the following error upon hitting left mouse button:
This particular error is because the tileset bitmap isn't loaded. However the tileset still displays on the screen (probably because everything died)
I should note that this component is *never* added to the scene. The initialization is in an extension of Component_CommandInterpreter
Object_StrategyGame just creates an Object_Tilemap and adds it to itself. Object_Tilemap has a Component_Tilemap component.
I understand this is such a stupidly specific question, but if anyone has any idea how I might go about getting a tilemap to behave like any other scene object, I'd greatly appreciate it.
I've been kind of fiddling with this for a couple of days. I'm trying to wrap gs.Tilemap as a component, but I'm having a hard time as it doesn't appear to be managed by the scene, and the tilemap simply appears everywhere, across scenes, on top of backgrounds, etc. After it gets created, it permanently exists.
My goal here was to create an extension that added a command to start a minigame involving tilemaps, while still using the visual VN maker portion for everything else.
I think the root of the problem lies in the dispose method. After disposing of the tilemap, It looks like it tries to render it still, and runs into problems because disposing of the tilemap disposes of the tileset bitmap.
I'll give an example, given the following Component_Tilemap:
Code:
class Component_Tilemap extends gs.Component_Visual {
constructor() {
super();
this.tilemap = new gs.Tilemap(Graphics.sceneViewport);
}
setup() {
super.setup();
console.log('setting up tilemap component');
const tiledMap = TileMaps[this.object.mapName];
this.tilemap.width = tiledMap.width;
this.tilemap.height = tiledMap.height;
this.tilemap.depth = tiledMap.layers.length;
this.tilemap.tileSize = tiledMap.tilewidth;
const mapData = [];
tiledMap.layers.forEach(l => mapData.push(...l.data.map(d => d - 1))); // Tiled exports .js files 1-indexed
this.tilemap.mapData = mapData;
this.tilemap.priorities = [];
const map = RecordManager.maps.find(m => m.name === this.object.mapName);
this.tilemap.tileset = ResourceManager.getBitmap(`Graphics/Pictures/${map.tileset.name}`);
this.tilemap.setup();
this.tilemap.update();
console.log("Setup tilemap");
}
dispose() {
super.dispose();
this.tilemap.dispose();
}
update() {
super.update();
this.tilemap.update();
}
}
gs.Component_Tilemap = Component_Tilemap;
and a custom ResourceLoader:
Code:
class TilemapResourceLoader extends gs.ResourceLoader.constructor {
constructor() {
super();
}
_loadEventCommandsGraphics(commands) {
super._loadEventCommandsGraphics(commands);
console.log(commands);
commands.forEach(c => {
switch(c.id) {
case "ext.StrategyGame": this.loadMap(c.params.name); break;
}
})
}
loadMap(name) {
const map = RecordManager.maps.find(m => m.name === name);
ResourceManager.getBitmap(`Graphics/Pictures/${map.tileset.name}`);
}
}
gs.ResourceLoader = new TilemapResourceLoader();
window.ResourceLoader = gs.ResourceLoader;
and the following scene:
You get the following error upon hitting left mouse button:
Code:
Uncaught TypeError: Cannot read property 'width' of null
at t.createFromImage (ENGINE.js:1)
at new t (ENGINE.js:1)
at t.setBitmap (ENGINE.js:1)
at t.render (ENGINE.js:1)
at t.drawTiles (ENGINE.js:1)
at e.draw (ENGINE.js:1)
at i.draw (ENGINE.js:1)
at t.snapshotToTexture (ENGINE.js:1)
at t.transition (ENGINE.js:1)
at Component_GameSceneBehavior.Component_SceneBehavior.transition (Component_SceneBehavior_7.js? [sm]:92)
This particular error is because the tileset bitmap isn't loaded. However the tileset still displays on the screen (probably because everything died)
I should note that this component is *never* added to the scene. The initialization is in an extension of Component_CommandInterpreter
Code:
class Component_StrategyGameCommandInterpreter extends gs.Component_CommandInterpreter {
constructor() {
super();
}
assignCommand(command) {
super.assignCommand(command);
console.log("Assigning command");
switch(command.id) {
case "ext.StrategyGame": command.execute = this.commandStrategyGame; break;
}
}
commandStrategyGame() {
const strategyGame = new gs.Object_StrategyGame(this.params.name);
strategyGame.setup();
//debugger;
//SceneManager.scene.behavior.addStrategyGame(strategyGame);
gs.GameNotifier.postMinorChange();
}
}
gs.Component_CommandInterpreter = Component_StrategyGameCommandInterpreter;
Object_StrategyGame just creates an Object_Tilemap and adds it to itself. Object_Tilemap has a Component_Tilemap component.
I understand this is such a stupidly specific question, but if anyone has any idea how I might go about getting a tilemap to behave like any other scene object, I'd greatly appreciate it.