Hi guys, I am building a Window_Selectable where each item is a picture, but it doesn't show the picture until I scroll the items.
This is the "relevant" code:
So, when I open this window on game I don't see any image:
But when I scroll down...
The pictures appears.
I noticed I can show them from the begining adding this code:
But as this function runs on every frame, images are drawn infinitely.
How to do it correctly? or Where is a good place to put this.drawAllItems()?
Thank you!
This is the "relevant" code:
Code:
function Window_BestiaryIndex() {
this.initialize.apply(this, arguments);
}
Window_BestiaryIndex.prototype = Object.create(Window_Selectable.prototype);
Window_BestiaryIndex.prototype.constructor = Window_BestiaryIndex;
Window_BestiaryIndex.prototype.drawItem = function(index) {
var enemy = this._list[index];
var rect = this.itemRect(index);
var name;
var bitmap;
bitmap = ImageManager.loadSvEnemy(enemy.battlerName, enemy.battlerHue);
_enemySprite = new Sprite();
_enemySprite.anchor.x = 0;
_enemySprite.anchor.y = 0;
_enemySprite.x = rect.x;
_enemySprite.y = rect.y;
_enemySprite.bitmap = bitmap;
var bmpW = _enemySprite.bitmap.width;
var bmpH = _enemySprite.bitmap.height;
var itmW = this.itemWidth();
var itmH = this.itemHeight();
if (_enemySprite.bitmap) {
var scale = 1;
if (bmpH > itmH) {
scale = itmH / bmpH;
}
_enemySprite.scale.x = scale;
_enemySprite.scale.y = scale;
}
var sclW = bitmap.width * scale;
var sclH = bitmap.height * scale;
this.contents.blt(_enemySprite.bitmap, 0, 0, bitmap.width, bitmap.height, rect.x + (itmW-sclW)/2, rect.y, sclW, sclH);
name = enemy.name;
this.drawText(name, rect.x, rect.y+80, rect.width);
};
So, when I open this window on game I don't see any image:
But when I scroll down...
The pictures appears.
I noticed I can show them from the begining adding this code:
Code:
Window_BestiaryIndex.prototype.update = function() {
Window_Selectable.prototype.update.call(this);
this.updateStatus();
this.drawAllItems();
};
But as this function runs on every frame, images are drawn infinitely.
How to do it correctly? or Where is a good place to put this.drawAllItems()?
Thank you!