Project1
标题: 绘制图标失败 [打印本页]
作者: 347780682 时间: 2022-10-5 01:33
标题: 绘制图标失败
新建工程 没有其他插件
为什么使用 this.drawIcon 绘制图标失败
(function () {
//继承菜单属性
var siakoMobi_create = Scene_Menu.prototype.create;
Scene_Menu.prototype.create = function () {
siakoMobi_create.call(this);
//把自己写的窗口类型做成构架函数并且继承给_cuostomWindow
this._cuostomWindow = new Window_Custom();
this._cuostomWindow.y = 340;
//把窗口显示在菜单里面
this.addChild(this._cuostomWindow);
};
//新建窗口
function Window_Custom() {
this.initialize.apply(this, arguments);
}
Window_Custom.prototype = Object.create(Window_Base.prototype);
Window_Custom.prototype.constructor = Window_Custom;
Window_Custom.prototype.initialize = function (x, y) {
var width = this.windowWidth();
var height = this.windowHeight();
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.refresh();
};
//窗口宽度
Window_Custom.prototype.windowWidth = function () {
return 240;
};
//窗口高度
Window_Custom.prototype.windowHeight = function () {
return 200;
};
//更新动态
Window_Custom.prototype.refresh = function () {
var x = this.textPadding();
var width = this.contents.width - this.textPadding() * 2;
this.contents.clear();
//显示文字
this.drawTextEx('这是窗口2', 0, 0);
//显示图标
this.drawIcon(64, 0, 30);
};
//窗口底层呼叫?
Window_Custom.prototype.open = function () {
this.refresh();
Window_Base.prototype.open.call(this);
};
})();
(function () {
//继承菜单属性
var siakoMobi_create = Scene_Menu.prototype.create;
Scene_Menu.prototype.create = function () {
siakoMobi_create.call(this);
//把自己写的窗口类型做成构架函数并且继承给_cuostomWindow
this._cuostomWindow = new Window_Custom();
this._cuostomWindow.y = 340;
//把窗口显示在菜单里面
this.addChild(this._cuostomWindow);
};
//新建窗口
function Window_Custom() {
this.initialize.apply(this, arguments);
}
Window_Custom.prototype = Object.create(Window_Base.prototype);
Window_Custom.prototype.constructor = Window_Custom;
Window_Custom.prototype.initialize = function (x, y) {
var width = this.windowWidth();
var height = this.windowHeight();
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.refresh();
};
//窗口宽度
Window_Custom.prototype.windowWidth = function () {
return 240;
};
//窗口高度
Window_Custom.prototype.windowHeight = function () {
return 200;
};
//更新动态
Window_Custom.prototype.refresh = function () {
var x = this.textPadding();
var width = this.contents.width - this.textPadding() * 2;
this.contents.clear();
//显示文字
this.drawTextEx('这是窗口2', 0, 0);
//显示图标
this.drawIcon(64, 0, 30);
};
//窗口底层呼叫?
Window_Custom.prototype.open = function () {
this.refresh();
Window_Base.prototype.open.call(this);
};
})();
作者: lqi991 时间: 2022-10-5 01:33
本帖最后由 lqi991 于 2022-10-5 15:10 编辑
# 如果图标图片没问题,那么可能 this.drawIcon 的原对象被修改了.
可以试试添加以下代码.
方法1:
Window_Custom.prototype.drawIcon = function(iconIndex, x, y) {
var bitmap = ImageManager.loadSystem('IconSet');
var pw = Window_Base._iconWidth;
var ph = Window_Base._iconHeight;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
};
Window_Custom.prototype.drawIcon = function(iconIndex, x, y) {
var bitmap = ImageManager.loadSystem('IconSet');
var pw = Window_Base._iconWidth;
var ph = Window_Base._iconHeight;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
this.contents.blt(bitmap, sx, sy, pw, ph, x, y);
};
方法2:
Window_Custom.prototype.drawIcon = function(iconIndex, x, y) {
var bitmap = ImageManager.loadSystem('IconSet');
var pw = Window_Base._iconWidth;
var ph = Window_Base._iconHeight;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
bitmap.addLoadListener(function(){ this.contents.blt(bitmap, sx, sy, pw, ph, x, y);}.bind(this));
};
Window_Custom.prototype.drawIcon = function(iconIndex, x, y) {
var bitmap = ImageManager.loadSystem('IconSet');
var pw = Window_Base._iconWidth;
var ph = Window_Base._iconHeight;
var sx = iconIndex % 16 * pw;
var sy = Math.floor(iconIndex / 16) * ph;
bitmap.addLoadListener(function(){ this.contents.blt(bitmap, sx, sy, pw, ph, x, y);}.bind(this));
};
作者: cenhangkai 时间: 2022-10-5 05:49
试了下初始工程,显示图标没有问题。
请你检查下MV引擎的安装目录,里面的 ICON 图片是否存在问题。
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |