MZ Problem drawing different sized icons

I just want to draw Icons in different sizes, therefore I've copied the code of Window_Base.prototype.drawIcon into the following function and added width/height parameters:
JavaScript:
Window_Base.prototype.drawSizedIcon = function(iconIndex, x, y, width, height)
{
    const bitmap = ImageManager.loadSystem("IconSet");
    const sw = ImageManager.iconWidth;
    const sh = ImageManager.iconHeight;
    const sx = (iconIndex % 16) *sw;
    const sy = Math.floor(iconIndex / 16) * sh;

    this.contents.blt(bitmap, sx, sy, sw, sh, x, y, width, height);
}

But for some reason this did not look like I've expected.
To better tell you what I mean take a look at the completely simplified IconSet I've uploaded here. I've surrounded Icon 17 with a red square 34 by 34 pixel, while Icons are 32 by 32 pixel.
Icon 17 starts at 17 % 16 = 1 * 32 = 32 and Math.floor(17 / 16) = 1 * 32 = 32, but the start of the red square is at Pixel (31, 31), yet if I modify Window_BattleStatus.prototype.refresh in the following way and start battle test I can see the red square:
JavaScript:
_refreshStatusWindow = Window_BattleStatus.prototype.refresh;
Window_BattleStatus.prototype.refresh = function()
{
    _refreshStatusWindow.call(this);
    
    const item2 = this.itemRect(2);
    const startX = item2.x;
    const colSpacing = this.colSpacing();
    const remainingWidth = this.innerWidth - colSpacing - startX;
    const height = item2.height / 3;
    const gaugeWidth = (remainingWidth - colSpacing) / 2;
    const iconSize = Math.floor(height);

    this.contents.fontSize = iconSize;

    const startX2 = startX + remainingWidth / 2 + colSpacing / 2;
    this.drawSizedIcon(17, startX2, item2.y, iconSize, iconSize);
    this.drawText("x " + $gameParty.gold(), startX2 + iconSize + 2, item2.y + 10, gaugeWidth - height, 'left');
    
    this.resetFontSettings();
}

BattleTest.PNG
Why? What did I do wrong? I don't want to see the sorroundings of the icons next to the icon I want to draw in larger size.

Additional Hint:
I've deactived all plugins except the one that contains my two modified functions I've posted here and it still looks like this.
bump
Hi there!

I did the almost the same thing here and it worked fine:
AppleScript:
Window_Base.prototype.drawSizedIcons = function(iconIndex, x, y, width, height){
    const bitmap = ImageManager.loadSystem("IconSet");
    const sw = ImageManager.iconWidth;
    const sh = ImageManager.iconHeight;
    const sx = (iconIndex % 16) * sw;
    const sy = Math.floor(iconIndex / 16) * sh;
    this.contents.blt(bitmap, sx, sy, sw, sh, x, y, width, height);
}

1662522069711.png


Maybe there is something wrong with your IconSet.png size?
Or even the calculations you did to draw it on the Window_BattleStatus?

Put a console log on the drawing function, just for we to see the values are correctly:
JavaScript:
Window_Base.prototype.drawSizedIcon = function(iconIndex, x, y, width, height)
{
    const bitmap = ImageManager.loadSystem("IconSet");
    const sw = ImageManager.iconWidth;
    const sh = ImageManager.iconHeight;
    const sx = (iconIndex % 16) *sw;
    const sy = Math.floor(iconIndex / 16) * sh;
    // console.log(sx, sy, sw, sh, x, y, width, height)
    this.contents.blt(bitmap, sx, sy, sw, sh, x, y, width, height);
}
1662564307185.png

Here is console output. I modified my function to call the normal drawIcon aswell. IconSet Size seems to be dividable by 16 in both directions,so it seems okay.

Here are my modified functions:
Spoiler: Functions
Code:
Window_Base.prototype.drawSizedIcon = function(iconIndex, x, y, width, height)
{
    const bitmap = ImageManager.loadSystem("IconSet");
    const sw = ImageManager.iconWidth;
    const sh = ImageManager.iconHeight;
    const sx = (iconIndex % 16) *sw;
    const sy = Math.floor(iconIndex / 16) * sh;

    console.log(`sx: ${sx} , sy: ${sy}, sw: ${sw}, sh: ${sh}, x: ${x}, y: ${y}, width: ${width}, height: ${height}`);
    console.log(`IconSet Measures: ${bitmap.height} x ${bitmap.width}`);
    this.contents.blt(bitmap, sx, sy, sw, sh, x, y, width, height);
}

_refreshStatusWindow = Window_BattleStatus.prototype.refresh;
Window_BattleStatus.prototype.refresh = function()
{
    _refreshStatusWindow.call(this);
    
    const item2 = this.itemRect(2);
    const startX = item2.x;
    const colSpacing = this.colSpacing();
    const remainingWidth = this.innerWidth - colSpacing - startX;
    const height = item2.height / 3;
    const gaugeWidth = (remainingWidth - colSpacing) / 2;
    const iconSize = Math.floor(height);

    this.contents.fontSize = iconSize;

    this.drawIcon(17, startX, item2.y);
    this.contents.fontSize = iconSize;
    this.drawText("x " + $gameParty.members()[0].currentExp(), startX + iconSize + 2, item2.y + 10, gaugeWidth - height, 'left');

    const startX2 = startX + remainingWidth / 2 + colSpacing / 2;
    this.drawSizedIcon(17, startX2, item2.y, iconSize, iconSize);
    this.drawText("x " + $gameParty.gold(), startX2 + iconSize + 2, item2.y + 10, gaugeWidth - height, 'left');
    
    this.resetFontSettings();
}

And I've tried something else. I've put another white square inside the 32 by 32 frame and a blue one outside the red one 36 by 36 and passed 256 instead of iconSize to my functions just to show that the size parameter does not matter:

As you can see on this screenshot, normal drawIcon draws the white square as expected, but the sized one does not draw the blue rectangle, even though size is now 256 instead of 64. That is why I think it does not depend on the size I pass to the functions.
1662564714689.png
Hm.... Did you try draw it on another window?
Maybe it is something related to the Window Battle Status?
No I've tried that aswell, also with the normal icon set. There it looked okay, but maybe just because all icons have borders that look the same, so it is just not noticable.
That is why I modified the normal MZ icon set again coloring the borders of the icons in different colors.
1662572877917.png
That's the modified part.
And that's how it looks on the new window:
1662572950340.png
The orange and the pink are slightly visible on each of the large icons. Seems Bitmap.prototype.blt for some reason draws slight parts of the sorounding icons for whatever reason. For my unbordered icons this looks not so good. Maybe I just copy them into seperate images and draw these seperate images instead.
I wonder if it's the scaling mode? Looks like MZ's core scripts use linear scaling for all bitmaps.

You could try loading this as a plugin, to set the iconset to nearest-neighbour scaling mode:
JavaScript:
/*:
 * @target MZ
 * @plugindesc Use nearest-neighbour scaling for the iconset.
 * @help Free to use and/or modify for any project, no credit required.
 */
void (alias => {
  Scene_Boot.prototype.loadSystemImages = function() {
    alias.apply(this, arguments);
    ImageManager.loadSystem("IconSet").smooth = false;
  };
})(Scene_Boot.prototype.loadSystemImages);
I wonder if it's the scaling mode? Looks like MZ's core scripts use linear scaling for all bitmaps.

You could try loading this as a plugin, to set the iconset to nearest-neighbour scaling mode:
JavaScript:
/*:
 * @target MZ
 * @plugindesc Use nearest-neighbour scaling for the iconset.
 * @help Free to use and/or modify for any project, no credit required.
 */
void (alias => {
  Scene_Boot.prototype.loadSystemImages = function() {
    alias.apply(this, arguments);
    ImageManager.loadSystem("IconSet").smooth = false;
  };
})(Scene_Boot.prototype.loadSystemImages);
Thanks, that did not work, but made me figure out a possible solution:
JavaScript:
Window_Test.prototype.refresh = function()
{
    this.drawIcon(282, 0, 0);
    this.drawSizedIcon(282, 40, 0, 256, 256);
    this.drawSizedIcon(283, 316, 0, 256, 256);
}
gives this result:
1662607896133.png
And
Code:
Window_Test.prototype.refresh = function()
{
    this.contents.context.imageSmoothingEnabled = false;
    this.drawIcon(282, 0, 0);
    this.drawSizedIcon(282, 40, 0, 256, 256);
    this.drawSizedIcon(283, 316, 0, 256, 256);
}
gives this result:
1662608043048.png

I may still just copy the icons I need in large into a seperate image, if the pixalated versions don't look any good at the window I need them.
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/problem-drawing-different-sized-icons.151067/