查看: 3090|回复: 6

[有事请教] 小白改写脚本遇到问题,关于物品图片加载

[复制链接]
梦石
0
星屑
582
在线时间
310 小时
注册时间
2016-2-29
回帖
149
发表于 2018-3-23 10:49:34 | 显示全部楼层 |阅读模式

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

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

×
小白改写脚本遇到问题

将下面的脚本

Window_ItemStatus.prototype.drawLargeIcon = function() {
    var iconIndex = this._item.iconIndex;
    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;
    var dw = Yanfly.Param.ItemIconSize;
    var dh = Yanfly.Param.ItemIconSize;
    var dx = (Window_Base._faceWidth - dw) / 2;
    var dy = (Window_Base._faceHeight - dh) / 2;
    this.contents._context.imageSmoothingEnabled = false;
    this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);
    this.contents._context.imageSmoothingEnabled = true;
};

改为

ImageManager.loadSystemItemIcon = function(filename, hue) {
    return this.loadBitmap('img/system/ItemIcon/', filename, hue, false);
};


Window_ItemStatus.prototype.drawLargeIcon = function() {
    /*
        改为加载,img/system/ItemIcon/文件夹里的,1号道具文件名是A1.png,2号武器文件名是W1.png
        如:
        img/system/ItemIcon/ I1.png
        img/system/ItemIcon/ W1.png
        img/system/ItemIcon/ A1.png
        原文件地址:var bitmap = ImageManager.loadSystem('IconSet');
    */
    var iconIndex = this._item.id;
    var bitmap,url='img/system/ItemIcon/';
    iconIndex -= this._item.id > Yanfly.Param.ItemStartingId ? 3000 : 0;
    if (DataManager.isItem(this._item)) {
        bitmap = ImageManager.loadSystemItemIcon('I' + iconIndex);
    }
    if (DataManager.isWeapon(this._item)) {
        bitmap = ImageManager.loadSystemItemIcon('W' + iconIndex);
    }
    if (DataManager.isArmor(this._item)) {
        bitmap = ImageManager.loadSystemItemIcon('A' + iconIndex);
    }
    if (DataManager.isSkill(this._item)) {
        bitmap = ImageManager.loadSystemItemIcon('S' + iconIndex);
    }
    var pw = Window_Base._iconWidth;
    var ph = Window_Base._iconHeight;
    var sx = 0;//iconIndex % 16 * pw;
    var sy = 0;//Math.floor(iconIndex / 16) * ph;
    var dw = Yanfly.Param.ItemIconSize;
    var dh = Yanfly.Param.ItemIconSize;
    var dx = (Window_Base._faceWidth - dw) / 2;
    var dy = (Window_Base._faceHeight - dh) / 2;
    this.contents._context.imageSmoothingEnabled = false;
    this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);
    this.contents._context.imageSmoothingEnabled = true;
};

加载不出图片,有什么好的解决方法吗?图片第一次加载没有渲染
梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
回帖
780
发表于 2018-3-23 13:57:08 | 显示全部楼层
this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);

改成这个 图片需要预读
        bitmap.addLoadListener(function() {
        this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);
          }.bind(this));

评分

参与人数 1赞 +1 收起 理由
白嫩白嫩的 + 1 叩拜12龄大佬

查看全部评分

回复 1 0

使用道具 举报

梦石
0
星屑
4399
在线时间
552 小时
注册时间
2017-12-2
回帖
41
发表于 2018-3-23 23:58:16 | 显示全部楼层
我的方案
[pre lang="javascript"]
Window_ItemStatus.prototype.drawLargeIcon = function() {
    /*
        获取物品索引
        加载IconSet.png
        改为加载,如果需要新的道具也有新的图像,就把
        代码index -= this._item.iconIndex > Yanfly.Param.ItemStartingId ?3000 : 0;去掉
        img/system/ItemIcon/ I1.png
        img/system/ItemIcon/ W1.png
        img/system/ItemIcon/ A1.png
        原文件地址:var bitmap = ImageManager.loadSystem('IconSet');
    */
    var bitmap;
    var sx = 0;
    var sy = 0;
    var index = this._item.id;
    var url = 'img/system/ItemIcon/';
    var iconIndex = this._item.iconIndex;
    var pw = Window_Base._iconWidth;
    var ph = Window_Base._iconHeight;
    var woaini = 1;
    index -= this._item.id > Yanfly.Param.ItemStartingId ? Yanfly.Param.ItemStartingId : 0;
    if (DataManager.isItem(this._item)) {
        var img = new Image();
        img.src= url + 'I' + index +'.png';
        img.onload = function() {
            bitmap = ImageManager.loadSystemItemIcon('I' + index);
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
        img.onerror = function() {
            sx = iconIndex % 16 * pw;
            sy = Math.floor(iconIndex / 16) * ph;
            bitmap = ImageManager.loadSystem('IconSet');
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
    }
    if (DataManager.isWeapon(this._item)) {
        var img = new Image();  
        img.src= url + 'W' + index +'.png';  
        img.onload = function() {
            bitmap = ImageManager.loadSystemItemIcon('W' + index);
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
        img.onerror = function() {
            bitmap = ImageManager.loadSystem('IconSet');
            sx = iconIndex % 16 * pw;
            sy = Math.floor(iconIndex / 16) * ph;
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
    }
    if (DataManager.isArmor(this._item)) {
        var img = new Image();  
        img.src= url + 'A' + index +'.png';
        img.onload = function() {
            bitmap = ImageManager.loadSystemItemIcon('A' + index);
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
        img.onerror = function() {
            bitmap = ImageManager.loadSystem('IconSet');
            sx = iconIndex % 16 * pw;
            sy = Math.floor(iconIndex / 16) * ph;
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
    }
    if (DataManager.isSkill(this._item)) {
        var img = new Image();  
        img.src= url + 'S' + index +'.png';
        img.onload = function() {
            bitmap = ImageManager.loadSystemItemIcon('S' + index);
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
        img.onerror = function() {
            bitmap = ImageManager.loadSystem('IconSet');
            sx = iconIndex % 16 * pw;
            sy = Math.floor(iconIndex / 16) * ph;
            this.aliasDrawLargeIcon(bitmap, sx, sy, pw, ph);
        }.bind(this);
    }
};

Window_ItemStatus.prototype.aliasDrawLargeIcon = function(bitmap, sx, sy, pw, ph) {
    var dw = Yanfly.Param.ItemIconSize;
    var dh = Yanfly.Param.ItemIconSize;
    var dx = (Window_Base._faceWidth - dw) / 2;
    var dy = (Window_Base._faceHeight - dh) / 2;
    this.contents._context.imageSmoothingEnabled = false;
    if (!bitmap.isReady()){
        bitmap.addLoadListener(function() {
            this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);
        }.bind(this));
     } else {
        this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);
    }
    this.contents._context.imageSmoothingEnabled = true;
}[/pre]
回复

使用道具 举报

梦石
0
星屑
582
在线时间
310 小时
注册时间
2016-2-29
回帖
149
 楼主| 发表于 2018-3-24 10:55:59 | 显示全部楼层
doranikofu 发表于 2018-3-23 13:57
this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh);

改成这个 图片需要预读

图片分辨率自动放大了N倍,求问这要怎么做?
回复

使用道具 举报

梦石
0
星屑
582
在线时间
310 小时
注册时间
2016-2-29
回帖
149
 楼主| 发表于 2018-3-24 12:31:32 | 显示全部楼层
是猪别乱叫 发表于 2018-3-24 10:55
图片分辨率自动放大了N倍,求问这要怎么做?

兄弟已帮我解决
回复

使用道具 举报

梦石
0
星屑
153
在线时间
26 小时
注册时间
2018-8-20
回帖
20
发表于 2018-8-24 03:38:17 | 显示全部楼层
感谢!!!!

点评

你这是在无限挖坟?  发表于 2018-8-24 03:58
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部