Create tileSet from graphics / renderTexture?

I want to generate a dynamic tileLayer that takes its tileSet from configurable settings. Is this even possible? Obviously, the normal mode is to load a tilemap, but I’m wondering if I can generate this dynamically using some combination of graphics / renderTextures

Was thinking I could do something like:

    this.texture = scene.add.renderTexture(0, 0, 200, 200);
    this.texture.draw(this.customGraphic); // A square graphic, with configurable "fill"
    this.texture.saveTexture('test-id');

My understanding was that this adds the “test-id” to the system TextureManager. But if I use this later in creating the tileLayer like so

tileMap.addTilesetImage('tile-set-name', 'test-id', tileWidth, tileHeight);

that blows up the Game, with the error:

WebGL: INVALID_OPERATION: bindTexture: attempt to use a deleted object

May have answered my own question: looks like there’s no need to go by renderTexture. Instead I did it via the Graphics object entirely:

    this.shape = scene.add.graphics();
    this.shape.setVisible(false);
    this.shape.fillStyle(0x000000);
    this.shape.fillRect(0, 0, 32, 32);
    this.shape.generateTexture('burp');
    this.shape.destroy();

That’s it; then when defining the addTilesetImage I just reference the new key…

tileMap.addTilesetImage('tile-set-name', 'burp', tileWidth, tileHeight);

I know that would happen: open the thread then discover the answer myself 30 seconds later :roll_eyes: :grin:

3 Likes