MZ (solved) Window_Scrollable does not render correctly when scrolling horizontal

Hey all,

so I want to make a Solar System and for this, I am trying to extend Window_Scrollable to enable horizontal scrolling. This is (part of) my code so far:

Spoiler
Code:
const alias_Window_createArrowSprites = Window.prototype._createArrowSprites;
Window.prototype._createArrowSprites = function() {
    alias_Window_createArrowSprites.call(this);

    this._leftArrowSprite = new Sprite();
    this._rightArrowSprite = new Sprite();
    this.addChild(this._leftArrowSprite);
    this.addChild(this._rightArrowSprite);
};

const alias_Window_updateArrows = Window.prototype._updateArrows;
Window.prototype._updateArrows = function() {
    alias_Window_updateArrows.call(this);
  
    this._leftArrowSprite.visible = this.isOpen() && this.leftArrowVisible;
    this._rightArrowSprite.visible = this.isOpen() && this.rightArrowVisible;
};

const alias_Window_refreshArrows = Window.prototype._refreshArrows;
Window.prototype._refreshArrows = function() {
    alias_Window_refreshArrows.call(this);

    const w = this._width;
    const h = this._height;
    const p = 24;
    const q = p / 2;
    const sx = 96 + p;
    const sy = 0 + p;

    this._rightArrowSprite.bitmap = this._windowskin;
    this._rightArrowSprite.anchor.x = 0.5;
    this._rightArrowSprite.anchor.y = 0.5;
    this._rightArrowSprite.setFrame(sx + p + q, sy + q, q, p);
    this._rightArrowSprite.move(w - q, h / 2);
    this._leftArrowSprite.bitmap = this._windowskin;
    this._leftArrowSprite.anchor.x = 0.5;
    this._leftArrowSprite.anchor.y = 0.5;
    this._leftArrowSprite.setFrame(sx, sy + q, q, p);
    this._leftArrowSprite.move(w / 2, q);
    this._leftArrowSprite.move(q, h / 2);
};


Window_Base.prototype.drawPicture = function(pictureName, x, y) {
    const bitmap = ImageManager.loadPicture(pictureName);
    const sw = bitmap.width;
    const sh = bitmap.height;
    const dx = x
    const dy = y;
    const sx = 0;
    const sy = 0;
    this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
};

function SolarSystemWindow() {
    this.initialize(...arguments);
}
SolarSystemWindow.prototype = Object.create(Window_Scrollable.prototype);
SolarSystemWindow.prototype.constructor = SolarSystemWindow;
SolarSystemWindow.prototype.initialize = function(rectangle) {
    Window_Scrollable.prototype.initialize.call(this, rectangle);
    this.refresh();
}
SolarSystemWindow.prototype.refresh = function() {
    this.createContents();
    const x1 = this.scrollX();
    const x2 = this.scrollX() + this.width;
    const y1 = this.scrollY();
    const y2 = this.scrollY() + this.height;
    MK.solarSystem.suns
        .filter(sun => x1 < sun.x && sun.x < x2 && y1 < sun.y && sun.y < y2)
        .map(sun => ({ x: sun.x - this.scrollX(), y: sun.y - this.scrollY() }))
        .forEach(sun => this.drawPicture('UI/ringed-planet', sun.x, sun.y));
}
SolarSystemWindow.prototype.updateArrows = function() {
    Window_Scrollable.prototype.updateArrows.call(this);
    this.rightArrowVisible = this._scrollX < this.maxScrollX();
    this.leftArrowVisible = this._scrollX > 0;
}
SolarSystemWindow.prototype.overallWidth = function() { return SOLAR_SYSTEM_WIDTH }
SolarSystemWindow.prototype.overallHeight = function() { return SOLAR_SYSTEM_HEIGHT }

It looks like (only when scrolling horizontally) all my objects are drawn block by block. As you can see here, only some stars on the left are drawn, although there are a lot more:

1660159293119.png


When I scroll bit more to the right, then out of sudden, all the suns are drawn:

1660159357754.png


EDIT:

Adding these lines made it work for me

Code:
SolarSystemWindow.prototype.itemWidth = function() { return 1 }
SolarSystemWindow.prototype.itemHeight = function() { return 1 }

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-window_scrollable-does-not-render-correctly-when-scrolling-horizontal.150302/