MZ Adding an image behind actor stats in Window_BattleStatus

So I've got this:
Code:
Window_BattleStatus.prototype.drawActorBattleCard = function(index) {
    this._actorBattleCard = new Sprite(ImageManager.loadPicture('actorBattleCard'));
    this.addChildToBack(this._actorBattleCard);
};

And I've applied it like this:
Code:
Window_BattleStatus.prototype.drawItem = function(index) {
    this.drawItemImage(index);
    this.drawItemStatus(index);
    this.drawActorBattleCard(index);
};

However it only draws behind the first actor and not on the other 2 (3 members total).

What am I missing here? I tried to draw it in Window_BattleStatus.prototype.drawItemStatus but it did the same thing there. Hmmm...
You cannot write this._actorBattleCard here. As you can see, the function drawActorBattleCard is called multiple times - one time for each party member. Right now, you are overriding this._actorBattleCard 3 times with the same value.

I think, this could help:

Code:
Window_BattleStatus.prototype.drawActorBattleCard = function(index) {
    this._actorBattleCards = this._actorBattleCards || [ ];
    this._actorBattleCards[index] = new Sprite(ImageManager.loadPicture('actorBattleCard'));
    this.addChildToBack(this._actorBattleCards[index]);
};
You cannot write this._actorBattleCard here. As you can see, the function drawActorBattleCard is called multiple times - one time for each party member. Right now, you are overriding this._actorBattleCard 3 times with the same value.

I think, this could help:

Code:
Window_BattleStatus.prototype.drawActorBattleCard = function(index) {
    this._actorBattleCards = this._actorBattleCards || [ ];
    this._actorBattleCards[index] = new Sprite(ImageManager.loadPicture('actorBattleCard'));
    this.addChildToBack(this._actorBattleCards[index]);
};

Thanks, @Aerosys ! However it still appears only once. I still call the function like this:

Code:
Window_BattleStatus.prototype.drawItem = function(index) {
    this.drawItemImage(index);
    this.drawItemStatus(index);
    this.drawActorBattleCard(index);
};

Should that be different perhaps?
Could it maybe be that your card sprite is now added 3 times, but they all share the same x/y position?
Could it maybe be that your card sprite is now added 3 times, but they all share the same x/y position?
That makes sense.

I've been trying a few things, namely seeing what the other functions do that draw actor stats and applied what I've seen to the drawActorBattleCard function. Like this:

Code:
Window_BattleStatus.prototype.drawActorBattleCard = function(index) {
    const rect = this.itemRect(index);
    this._actorBattleCards = this._actorBattleCards || [];
    this._actorBattleCards[index] = new Sprite(ImageManager.loadPicture('actorBattleCard'));
    this.addChildToBack(this._actorBattleCards[index], rect.x, rect.y);
};

It still seems to either draw one or draw them all over top each other. Still trying things out, but scratching my head at the same time.
itemRect is already a good way to go. The only thing you have been missing is the sprite's move method.

Code:
const rect = this.itemRect(index);

this._actorBattleCards = this._actorBattleCards || [];
this._actorBattleCards[index] = new Sprite(ImageManager.loadPicture('actorBattleCard'));
this._actorBattleCards[index].move(rect.x, rect.y);

this.addChildToBack(this._actorBattleCards[index]);
itemRect is already a good way to go. The only thing you have been missing is the sprite's move method.

Code:
const rect = this.itemRect(index);

this._actorBattleCards = this._actorBattleCards || [];
this._actorBattleCards[index] = new Sprite(ImageManager.loadPicture('actorBattleCard'));
this._actorBattleCards[index].move(rect.x, rect.y);

this.addChildToBack(this._actorBattleCards[index]);
Aha! That worked! The move method is new to me, coming from MV. I don't know that I had seen that one at all when I was using the engine. That's one to remember, haha.

Thanks for the guidance/aid, @Aerosys ! I appreciate it!

Original thread: https://forums.rpgmakerweb.com/threads/adding-an-image-behind-actor-stats-in-window_battlestatus.176031/