查看: 2440|回复: 2

[有事请教] 绘制图标失败

[复制链接]
梦石
0
星屑
6963
在线时间
1557 小时
注册时间
2011-6-14
回帖
425
发表于 2022-10-5 01:33:55 | 显示全部楼层 |阅读模式
悬赏500星屑已解决
新建工程 没有其他插件
为什么使用 this.drawIcon 绘制图标失败
QQ图片20221005013257.png

[pre lang="javascript"]
(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);
    };

})();[/pre]

最佳答案

查看完整内容

# 如果图标图片没问题,那么可能 this.drawIcon 的原对象被修改了. 可以试试添加以下代码. 方法1: [pre lang="javascript"]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.c ...
梦石
0
星屑
5626
在线时间
177 小时
注册时间
2011-6-3
回帖
29
发表于 2022-10-5 01:33:56 | 显示全部楼层
本帖最后由 lqi991 于 2022-10-5 15:10 编辑

# 如果图标图片没问题,那么可能  this.drawIcon 的原对象被修改了.
    可以试试添加以下代码.
方法1:
[pre lang="javascript"]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);
};[/pre]
方法2:
[pre lang="javascript"]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));
};[/pre]
# 基于RMMV/MZ基础编写插件,持续更新,请多多支持.
# 需求人多的优先编写!最新消息请关注下面通道.

[插件交流群][个人插件网]
回复

使用道具 举报

梦石
0
星屑
4649
在线时间
570 小时
注册时间
2018-11-12
回帖
120
发表于 2022-10-5 05:49:56 | 显示全部楼层
试了下初始工程,显示图标没有问题。
请你检查下MV引擎的安装目录,里面的  ICON 图片是否存在问题。
1.png 2.png
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部