Change Face based on State with MOG_BattleHUD
Hello people, as you could've seen in my last post I had a problem with MOG_BattleHUD since I desired to update the face when your actor is affected by a status.Since I haven't found anything helpful, I had to look at the code and do it myself, so here's a little tutorial.
HOW TO UPDATE FACES BASED ON STATE
First of all, by taking a look at the code we notice that the functions we'll have to modify are the functions related to "face" voice, since "face" is the variable that loads our image to be displayed.
The first function is create_face, and is the one that loads the images and assigns variables for positions etc.
In the clean Plugin, it looks like this:
JavaScript:
Battle_Hud.prototype.create_face = function() { if (String(Moghunter.bhud_face_visible) != "true") {return}; this.removeChild(this._face); if (!this._battler) {return}; this._face = new Sprite(ImageManager.loadBHud("Face_" + this._battler._actorId)); this._face.anchor.x = 0.5; this._face.anchor.y = 0.5; this._face_data = ; this._face.ph = 0; this._face.animation = [-1,0,0,0,0,0,0,0,0]; this._face.breathEffect = this._battler._bhud.faceBreath; this._face.scaleY = 0; if (String(Moghunter.bhud_face_shake) === "true") {this._face_data = true} if (String(Moghunter.bhud_face_animated) === "true") {this._face_data = true} this._battler._bhud_face_data = this.addChild(this._face);};
But since I need to load a different face, we should initialize it:
JavaScript:
Battle_Hud.prototype.create_face = function() { if (String(Moghunter.bhud_face_visible) != "true") {return}; this.removeChild(this._face); this.removeChild(this._alternateFace); if (!this._battler) {return}; this._face = new Sprite(ImageManager.loadBHud("Face_" + this._battler._actorId)); this._alternateFace = new Sprite(ImageManager.loadBHud("Face_" + this._battler._actorId + "_Alt")); this._alternateFace.visible = false; // Inizialmente nascosta this._face.anchor.x = 0.5; this._face.anchor.y = 0.5; this._alternateFace.anchor.x = 0.5; this._alternateFace.anchor.y = 0.5; this._face_data = ; this._face.ph = 0; this._face.animation = [-1,0,0,0,0,0,0,0,0]; this._face.breathEffect = this._battler._bhud.faceBreath; this._face.scaleY = 0; this._alternateFace_data = ; this._alternateFace.ph = 0; this._alternateFace.animation = [-1,0,0,0,0,0,0,0,0]; this._alternateFace.breathEffect = this._battler._bhud.faceBreath; this._alternateFace.scaleY = 0; if (String(Moghunter.bhud_face_shake) === "true") {this._face_data = true} if (String(Moghunter.bhud_face_animated) === "true") {this._face_data = true} this._battler._bhud_face_data = ; this.addChild(this._face); this.addChild(this._alternateFace);};
The parameters are very similar, and typically this will be true for more or less all functions (unless you want to perform something specific).
Now that our new face is loaded, we need a logic to show it when the State (or another condition) is verified.
The plugin calls constantly the function update_face to check if there is any need to perform an update of some sort, usually just for checking that everything is okey.
Here we will introduce our logic. The clean plugin code for update_face looks like this:
JavaScript:
Battle_Hud.prototype.update_face = function() { if (!this._face) {return}; if (!this._face.bitmap.isReady()) {return}; if (this._face_data && this._face_data != this._battler._bhud_face_data) {this.refresh_face();}; this.update_face_animation(); this.update_face_shake(); this.update_face_zoom(); if (this._face.breathEffect) {this.updateFaceEffects()};};
But we'll have to modify it, and this is what I've done:
JavaScript:
Battle_Hud.prototype.update_face = function() { if (!this._face) {return}; if (!this._face.bitmap.isReady()) {return}; if (!this._alternateFace) {return}; if (!this._alternateFace.bitmap.isReady()) {return}; if (this._battler.isStateAffected(13)) { this._face.visible = false; this._alternateFace.visible = true; } else { this._face.visible = true; this._alternateFace.visible = false; } if (this._face_data && this._face_data != this._battler._bhud_face_data) {this.refresh_face();}; this.update_face_animation(); this.update_face_shake(); this.update_face_zoom(); // Same for alternateFace if (!this._alternateFace) {return}; if (!this._alternateFace.bitmap.isReady()) {return}; if (this._alternateFace_data && this._alternateFace_data != this._battler._bhud_face_data) {this.refresh_face();}; this.update_face_animation(); this.update_face_shake(); this.update_face_zoom(); if (this._face.breathEffect) {this.updateFaceEffects()}; if (this._alternateFace.visible === true && this._alternateFace.breathEffect) {this.updateFaceEffects()}; };
We checked if the current battler is affected by the State (in my case, the one with ID 13), and then we switched the visibility of the original face to the new one we initialized.
Also, we have to be sure to perform all the controls invoked on the face variable on our alternateFace.
And this is more or less the logic for all the other face-related functions.
Of course, I let the check equal to the ones performed on the face variable because I created the pictures (the standard and the alternate one) together, so they are very similar and have the same resolutions, DPI, and sizes. Be sure to modify those parameters if the two pictures aren't similar.
Below, I will post all the other functions I modified.
Hope this will help you, have a good day!
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
JavaScript:
//==============================// * update Face Effects//==============================Battle_Hud.prototype.updateFaceEffects = function() { if (this._face_data == 0 || this._face_data == 3) { this._face.anchor.y = 1; this._face.y = this._pos_y + Moghunter.bhud_face_pos_y + this._face.height / 2; this._alternateFace.anchor.y = 1; this._alternateFace.y = this._pos_y + Moghunter.bhud_face_pos_y + this._alternateFace.height / 2; this.updateBreathEffect() } else { this._face.anchor.y = 0.5; this._face.y = this._pos_y + Moghunter.bhud_face_pos_y; this._alternateFace.anchor.y = 0.5; this._alternateFace.y = this._pos_y + Moghunter.bhud_face_pos_y; };};//==============================// * set Breath Effect//==============================Battle_Hud.prototype.setBreathEffect = function() { this._face.animation = 0; var rds = Math.randomInt(100); var rds2 = rds * 0.0000001; this._face.animation = 0.000005; this._face.animation = 0.0002; var int = this._face.animation; var int2 = (Math.randomInt(int) * 0.0001).toFixed(4); this._face.animation = int2; this._face.animation = Math.randomInt(80) // Alternate FACE this._alternateFace.animation = 0; this._alternateFace.animation = 0.000005; this._alternateFace.animation = 0.0002; var int = this._alternateFace.animation; this._alternateFace.animation = int2; this._alternateFace.animation = Math.randomInt(80) };//==============================// * update Breath Effect//==============================Battle_Hud.prototype.updateBreathEffect = function() { this._face.scale.y = 1.00 + this._face.scaleY; if (this._face.animation == -1) { if (this._face.bitmap.isReady()) {this.setBreathEffect()} return } if (this._face.animation > 0) { this._face.animation-- return } if (this._face.animation == 0) { this._face.animation -= this._face.animation this._face.scaleY += this._face.animation; if (this._face.animation <= -this._face.animation) { this._face.animation = -this._face.animation this._face.animation = 1; }; } else { this._face.animation += this._face.animation this._face.scaleY += this._face.animation; if (this._face.animation >= this._face.animation) { this._face.animation = this._face.animation this._face.animation = 0; }; }; // alternate Face this._alternateFace.scale.y = 1.00 + this._alternateFace.scaleY; if (this._alternateFace.animation == -1) { if (this._alternateFace.bitmap.isReady()) {this.setBreathEffect()} return } if (this._alternateFace.animation > 0) { this._alternateFace.animation-- return } if (this._alternateFace.animation == 0) { this._alternateFace.animation -= this._alternateFace.animation this._alternateFace.scaleY += this._alternateFace.animation; if (this._alternateFace.animation <= -this._alternateFace.animation) { this._alternateFace.animation = -this._alternateFace.animation this._alternateFace.animation = 1; }; } else { this._alternateFace.animation += this._alternateFace.animation this._alternateFace.scaleY += this._alternateFace.animation; if (this._alternateFace.animation >= this._alternateFace.animation) { this._alternateFace.animation = this._alternateFace.animation this._alternateFace.animation = 0; }; }; };//==============================// * Refresh Face//==============================Battle_Hud.prototype.refresh_face = function() { this._face_data = this._battler._bhud_face_data; var cw = this._face.bitmap.width / 5; var ch = this._face.bitmap.height; this._face.setFrame(cw * this._face_data, 0, cw, ch); // Alternate Face // this._face_data = this._battler._bhud_face_data; var acw = this._alternateFace.bitmap.width / 5; var ach = this._alternateFace.bitmap.height; this._alternateFace.setFrame(cw * this._face_data, 0, acw, ach); };//==============================// * Update Face Shake//==============================Battle_Hud.prototype.update_face_shake = function() { this._face.x = this._pos_x + Moghunter.bhud_face_pos_x; this._alternateFace.x = this._pos_x + Moghunter.bhud_face_pos_x; if (this._face_data && this._battler._bhud_face_data > 0) {this._battler._bhud_face_data -= 1; this._face.x = this._pos_x + Moghunter.bhud_face_pos_x + ((Math.random() * 12) - 6); this._alternateFace.x = this._pos_x + Moghunter.bhud_face_pos_x + ((Math.random() * 12) - 6); };};//==============================// * Refresh Position//==============================Battle_Hud.prototype.refresh_position = function() { this.set_hud_position(); this.create_sprites(); this._layout.x = this._pos_x; this._layout.y = this._pos_y; if (this._face) { this._face.x = this._pos_x + Moghunter.bhud_face_pos_x; this._face.y = this._pos_y + Moghunter.bhud_face_pos_y + this._face.ph; }; if (this._alternateFace) { this._alternateFace.x = this._pos_x + Moghunter.bhud_face_pos_x; this._alternateFace.y = this._pos_y + Moghunter.bhud_face_pos_y + this.alternateFace.ph; }; if (this._turn) { this._turn.x = this._pos_x + (this._turn.width / 2) + Moghunter.bhud_turn_pos_x; this._turn.y = this._pos_y + (this._turn.height / 2) + Moghunter.bhud_turn_pos_y; }; if (this._layout2) { this._layout2.x = this._pos_x + Moghunter.bhud_layoverlay_x; this._layout2.y = this._pos_y + Moghunter.bhud_layoverlay_y; }; if (this._face) {this._battler._face_pos = }; if (this.alternateFace) {this._battler._face_pos = };};
If you find this useful, please just mention me.
Free for everyone to use and free to update it if you find a better solution.
data/attachments/smilies/mzcelebration/vxmegane.png
本贴来自国际rpgmaker官方论坛作者:nProd处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/change-face-based-on-state-with-mog_battlehud.170135/
页:
[1]