Не удается прочитать свойство в плагине JavaScript

Я создаю собственный плагин javascript для игры, который заменяет стандартное меню на пользовательское. У меня это работает до такой степени, что цель состоит в том, чтобы создать новое окно меню, которое отображает изображение всякий раз, когда выбирается элемент в списке.

Всякий раз, когда я загружаю свой код, я получаю ошибку

TypeError: Невозможно прочитать свойство 'setImageName' из неопределенного

Я знаю, какой именно фрагмент кода используется, но я не могу понять, почему он не работает, хотя я уверен, что для этого есть простая причина. Ниже приведен раздел кода, с которым это связано, может кто-нибудь помочь мне найти проблему?

Спасибо

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

Window_DrawTheItemPictures.prototype = Object.create(Window_Base.prototype);
Window_DrawTheItemPictures.prototype.constructor = Window_DrawTheItemPictures;

Window_DrawTheItemPictures.prototype.initialize = function(x, y){
    var x = 420;
    var y = 20;
    var width = 350;
    var height = 590;
    Window_Base.prototype.initialize.call(this, x, y, width, height);
    this.refresh();
};


Scene_Item.prototype.create = function() {
    Scene_ItemBase.prototype.create.call(this);
    this.createCategoryWindow();
    this.createHelpWindow();
    this.createItemWindow();

    this._itemPicturesWindow = new Window_DrawTheItemPictures();
    this.addWindow(this._itemPicturesWindow);
    this._itemWindow._itemPicturesWindow = this._itemPicturesWindow;

    console.log(this._itemWindow._itemPicturesWindow === this._itemPicturesWindow);
};

Scene_Item.prototype.createCategoryWindow = function() {
    this._categoryWindow = new Window_ItemCategory();
    this._categoryWindow.setHelpWindow(this._helpWindow);
    this._categoryWindow.x = 60;
    this._categoryWindow.y = 30;    
    this._categoryWindow.width = 350;
    this._categoryWindow.opacity = 0;
    this._categoryWindow.setHandler('ok',     this.onCategoryOk.bind(this));
    this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
    this.addWindow(this._categoryWindow);
};

Window_ItemCategory.prototype.makeCommandList = function() {
    this.addCommand(TextManager.item,    'item');
    this.addCommand(TextManager.keyItem, 'keyItem');
};

Scene_Item.prototype.createItemWindow = function() {
    var wy = this._categoryWindow.y + this._categoryWindow.height;
    var wh = Graphics.boxHeight - wy - 20;
    this._itemWindow = new Window_ItemList(60, wy, 350, wh);
    this._itemWindow.opacity = 0;
    this._itemWindow.setHelpWindow(this._helpWindow);
    this._itemWindow.setHandler('ok',     this.onItemOk.bind(this));
    this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
    this.addWindow(this._itemWindow);
    this._categoryWindow.setItemWindow(this._itemWindow);
};

Scene_ItemBase.prototype.useItem = function() {
    this.playSeForItem();
    this.user().useItem(this.item());
    this.applyItem();
    this.checkCommonEvent();
    this.checkGameover();
};

Window_ItemCategory.prototype.maxCols = function() {
    return 2;
};

Window_ItemList.prototype.maxCols = function() {
    return 1;
};

Window_ItemList.prototype.spacing = function() {
    return 24;
};


Window_ItemList.prototype.select = function(index) {
    Window_Selectable.prototype.select.call(this, index);
    this.refreshMyItemPictureWindow(this.item());
};

Window_ItemList.prototype.refreshMyItemPictureWindow = function(item) {
    this._itemPicturesWindow.setImageName(item);
};

Window_DrawTheItemPictures.prototype.setImageName = function(item) {
    this._imageName = item.name;
    this.refresh();
};

Window_DrawTheItemPictures.prototype.refresh = function() {
    if (this._imageName !== undefined) {
        var bitmap = ImageManager.loadPicture(this._imageName);
        var sx = 60; //x-coordinate in source picture
        var sy = 100; //y-coordinate in source picture
        var sw = 1; //width in source picture
        var sh = 100; //height in source picture
        var dx = 0; //x-coordinate in the destination window
        var dy = 0; //y-coordinate in the destination window
        this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
    }
};

0 ответов

Другие вопросы по тегам