Hi there!
I believe you need to do that on the drawItemBackground or drawBackgroundRect method, inherited from Window_Selectable:
JavaScript:
Window_Selectable.prototype.drawItemBackground = function(index) {
const rect = this.itemRect(index);
this.drawBackgroundRect(rect);
};
Window_Selectable.prototype.drawBackgroundRect = function(rect) {
const c1 = ColorManager.itemBackColor1();
const c2 = ColorManager.itemBackColor2();
const x = rect.x;
const y = rect.y;
const w = rect.width;
const h = rect.height;
this.contentsBack.gradientFillRect(x, y, w, h, c1, c2, true);
this.contentsBack.strokeRect(x, y, w, h, c1);
};
These methods are the ones that draw that dark rectangle on the commands.
So if you want to draw an image behind the text, you can draw it right at the end of the
drawBackgroundRect , on the
contentsBack
Or you could draw it before the drawItem, inherited from Window_Command:
JavaScript:
Window_Command.prototype.drawItem = function(index) {
const rect = this.itemLineRect(index);
const align = this.itemTextAlign();
this.resetTextColor();
this.changePaintOpacity(this.isCommandEnabled(index));
this.drawText(this.commandName(index), rect.x, rect.y, rect.width, align);
};
To draw an image, you could either create a sprite and add it as a child on the window and set its position according to the dark background rect(
this.itemRect(index))
JavaScript:
const rect = this.itemRect(index)
const image = ImageManager.loadPicture(filename)
const spr = new Sprite(image)
this.addChild(spr)
spr.move(rect.x, rect.y)
Or you can draw it directly on the contentsBack(I think this is best than above method):
- "s" means Source
- "d" means Destination
- "w" means the width
- "h" means the height
JavaScript:
const image = ImageManager.loadPicture(filename)
const rect = this.itemRect(index)
image.addLoadListener(() => {
const sx = 0
const sy = 0
const sw = image.width
const sh = image.height
const dx = rect.x
const dy = rect.y
const dw = rect.width
const dh = rect.height
this.contentsBack.blt(image, sx, sy, sw, sh, dx, dy, dw, dh)
})
If you do not want to fit/stretch the image into the dark rectangle, you can choose not to use
dw and
dh, and they will be the same value as the image width/height.
for reference of the BLT method from bitmap:
JavaScript:
Bitmap.prototype.blt = function(source, sx, sy, sw, sh, dx, dy, dw, dh) {
dw = dw || sw;
dh = dh || sh;
try {
const image = source._canvas || source._image;
this.context.globalCompositeOperation = "source-over";
this.context.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh);
this._baseTexture.update();
} catch (e) {
//
}
};
Hope I didn't miss anything! ^^