Hello,
Can someone help me with a piece of code to draw Game_Timer inside a window?
Thx
Can someone help me with a piece of code to draw Game_Timer inside a window?
Thx
// TimerWindow.js
// Created on 8/21/2018
/*:
* @plugindesc This plugin is meant to display the game timer in a window.
* @author Yethwhinger
* @help This plugin replaces the game timer sprite with a
* game timer window.
*/
//-----------------------------------------------------------------------------
// Window_Timer
//
// The window for displaying the game timer.
function Window_Timer() {
this.initialize.apply(this, arguments);
}
Window_Timer.prototype = Object.create(Window_Base.prototype);
Window_Timer.prototype.constructor = Window_Timer;
Window_Timer.prototype.initialize = function (x, y, w) {
var height = this.windowHeight();
Window_Base.prototype.initialize.call(this, x, y, w, height);
this._seconds = 0;
this.openness = 0;
this.refresh();
};
Window_Timer.prototype.windowHeight = function () {
return this.fittingHeight(1);
};
Window_Timer.prototype.refresh = function () {
var x = this.textPadding();
var width = this.contents.width - this.textPadding() * 2;
this.contents.clear();
this.drawText(this.value(), x, 0, width);
};
Window_Timer.prototype.value = function () {
return Sprite_Timer.prototype.timerText.call(this);
};
Window_Timer.prototype.open = function () {
this.refresh();
Window_Base.prototype.open.call(this);
};
Window_Timer.prototype.update = function () {
if (this._seconds !== $gameTimer.seconds()) {
this._seconds = $gameTimer.seconds();
this.refresh();
}
Window_Base.prototype.update.call(this);
this.updateVisibility();
};
Window_Timer.prototype.updateVisibility = function () {
if (!$gameTimer.isWorking()) {
this.close();
}
else {
this.open();
}
};
//----------------------------
// Changes to Spriteset_Base
//----------------------------
Spriteset_Base.prototype.createUpperLayer = function () {
this.createPictures();
this.createScreenSprites();
};
//----------------------------
// Changes to Scene_Map
//----------------------------
var _Scene_Map_createAllWindows = Scene_Map.prototype.createAllWindows;
Scene_Map.prototype.createAllWindows = function () {
this.createTimerWindow();
_Scene_Map_createAllWindows.call(this);
};
Scene_Map.prototype.createTimerWindow = function () {
var w = 120;
var x = Graphics.width - w;
var y = 0;
this._timerWindow = new Window_Timer(x, y, w);
this.addChild(this._timerWindow);
};
Original thread: https://forums.rpgmakerweb.com/threads/game_timer-in-window.98863/