ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.32k stars 254 forks source link

setOptions layout is not working #172

Closed kosinaz closed 4 years ago

kosinaz commented 4 years ago

I tried it several ways, and finally, I gave a chance to the interactive manual, but it does nothing. I tried layout: "hex" and even layout: "rect" on an already rect display and then the display just got cleared.

var display = new ROT.Display({width:20, height:5});
SHOW(display.getContainer());
display.setOptions({
    layout: "rect",
    width: 30,
    fontSize: 8,
    fontStyle: "bold",
    bg: "#a00"
});

Without the layout: "rect" line it works fine.

I would like to use this method to change between rect and tile layout at runtime. Based on the code this should be a possibility.

            if (options.layout) {
                let ctor = BACKENDS[options.layout];
                this._backend = new ctor();
            }
            this._backend.setOptions(this._options);
            this._dirty = true;

But it does nothing. No error, no crash, just an empty display even if I draw on it.

ondras commented 4 years ago

Hi @kosinaz,

I would guess that you need to re-append the display's container. Switching the backend probably creates a new HTML container node that shall be appended as necessary.

Ref: https://github.com/ondras/rot.js/blob/master/src/display/display.ts#L113

kosinaz commented 4 years ago

It works like a charm! Thank you! I need to remove the previous canvas every time the layout is changed, but it's ok. Thanks for the quick support!