I probably misused the "update" term.
How do I reflect changes to a window's sprite if, for example, a variable changes from 1 to 2 which determines which .png graphic to display:
if ($gameVariables.value(1) == 1) {
this.drawPicturename('PicNameA', 0, 0);
}
if ($gameVariables.value(1) >= 2) {
this.drawPicturename('PicNameB', 0, 0);
}
Window_Name.prototype.drawPicturename = function(filename, x, y) {
var bitmap = ImageManager.loadPicture(filename);
this.contents.blt(bitmap, 0, 0, bitmap.width, bitmap.height, x, y);
};
==============
I hope to update sprites depending on certain changes in battle even to like (this is an example):
if 2 enemies, draw picture of sun
if 1 enemy left after defeating other one, update the sun to picture of moon
Seems like when I draw the initial picture based on condition, it doesn't change once it meets another criteria.
Thanks
With the contents canvas on windows the sprites "bleed" onto the canvas so to speak. So 10 sprites in a window become one big canvas that is static. Meaning, you have to clear the contents before drawing a new picture.
So try this first:
JavaScript:if ($gameVariables.value(1) == 1) {
this.contents.clear();
this.drawPicturename('PicNameA', 0, 0);
}
However, there is another way to mess with sprites and have more control over them.
JavaScript:Window_Name.prototype.drawPicturename = function(filename, x, y) {
//create a sprite to house the bitmap
let spr = new Sprite();
let bitmap = ImageManager.loadPicture(filename);
spr.bitmap = bitmap;
//I'm sure there is a spr.position.set function or something like that
//for easiert coding
//note that x and y are anchored at the window's corner, not the screen's
spr.x = x;
spr.y = y;
//add the sprite to a new window property named after the file
this["_" + filename] = spr;
//add it as a child otherwise you won't see it
this.addChild(spr);
};
This way you have more control over the sprites. You can actively move them around, set opacity etc.
You can then access the sprite like this:
Window_Name._filename
I suggest you create both images in the beginning and set only one to visible and then switch visibility as necessary to show either moon or sun. Let me know if this helped.