查看: 1829|回复: 4

[有事请教] 关于游戏里计时器的问题?

[复制链接]
梦石
0
星屑
5274
在线时间
733 小时
注册时间
2013-1-18
回帖
525
发表于 2023-3-4 13:01:36 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
MV里面使用计时器,会在屏幕右上角显示倒计时。
我有两个问题请大佬们帮忙:
1.如何改变倒计时显示的位置?
2.我想在这个倒计时前面加上几个字,请问该怎么操作?
3.该设置我不想使用任何插件。
梦石
0
星屑
119
在线时间
13 小时
注册时间
2021-12-13
回帖
4
发表于 2023-3-4 21:56:15 | 显示全部楼层
要么改代码,要么拿显示图片自己做个计时器。

点评

是个好想法,感谢!  发表于 2023-3-4 22:40
回复

使用道具 举报

梦石
2
星屑
8479
在线时间
463 小时
注册时间
2021-12-4
回帖
486

MZ评测员

发表于 2023-3-4 23:14:15 | 显示全部楼层
//-----------------------------------------------------------------------------
// Sprite_Timer
//
// The sprite for displaying the timer.

function Sprite_Timer() {
    this.initialize.apply(this, arguments);
}

Sprite_Timer.prototype = Object.create(Sprite.prototype);
Sprite_Timer.prototype.constructor = Sprite_Timer;

Sprite_Timer.prototype.initialize = function() {
    Sprite.prototype.initialize.call(this);
    this._seconds = 0;
    this.createBitmap();
    this.update();
};

Sprite_Timer.prototype.createBitmap = function() {
    this.bitmap = new Bitmap(96, 48);
    this.bitmap.fontSize = 32;
};

Sprite_Timer.prototype.update = function() {
    Sprite.prototype.update.call(this);
    this.updateBitmap();
    this.updatePosition();
    this.updateVisibility();
};

Sprite_Timer.prototype.updateBitmap = function() {
    if (this._seconds !== $gameTimer.seconds()) {
        this._seconds = $gameTimer.seconds();
        this.redraw();
    }
};

Sprite_Timer.prototype.redraw = function() {
    var text = this.timerText();
    var width = this.bitmap.width;
    var height = this.bitmap.height;
    this.bitmap.clear();
    this.bitmap.drawText(text, 0, 0, width, height, 'center');
};

Sprite_Timer.prototype.timerText = function() {
    var min = Math.floor(this._seconds / 60) % 60;
    var sec = this._seconds % 60;
    return min.padZero(2) + ':' + sec.padZero(2);
};

Sprite_Timer.prototype.updatePosition = function() {
    this.x = Graphics.width - this.bitmap.width;
    this.y = 0;
};

Sprite_Timer.prototype.updateVisibility = function() {
    this.visible = $gameTimer.isWorking();
};

以上代码位于rpg_sprites.js第2000行,可以修改updatePosition和timerText来分别修改位置和文字格式哦。

点评

感谢大佬,还想问一个问题。如果我想让这个计时器的倒计时放在角色头顶,会跟着人物走,该怎么弄呢?  发表于 2023-3-5 16:11

评分

参与人数 1赞 +1 收起 理由
xiamumomo + 1 塞糖

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部