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

Status
Not open for further replies.

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
752
Reaction score
716
First Language
german
Primarily Uses
RMMZ
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:

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 }
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,943
Reaction score
6,304
First Language
Dutch
Primarily Uses
RMXP

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.

 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts


Clarn Hold
(No storylines)
There was a tutorial on how to draw anime eyes. Just draw Among Us. So I tried.
Screenshot_107.jpg
DamageActor3_7.png added!
index.php

Making a "characters first appearance" drawing for my game. Now I just have to finish the sprite art animation for her grand entrance.​
ScreenShot_9_24_2022_7_56_24.png
New area being started today. It leads to one of the games 2 optional bosses.

Forum statistics

Threads
125,540
Messages
1,171,815
Members
164,611
Latest member
anonymouss
Top