new Bitmapのエラー

ppp
記事: 43
登録日時: 2022年9月28日(水) 21:50

new Bitmapのエラー

投稿記事by ppp » 2023年11月06日(月) 00:21

質問失礼します。SAN_MapGeneratorを改変してミニマップを表示したいので製作途中ですが以下のようにコードを書きました。

コード: 全て選択

//-----------------------------------------------------------------------------
// Sprite_Minimap
//
// ミニマップジェネレーター

//ミニマップ生成
function Sprite_Minimap() {
    this.initialize.apply(this, arguments);
}

Sprite_Minimap.prototype = Object.create(Sprite_Base.prototype);
Sprite_Minimap.prototype.constructor = Sprite_Minimap;

//ミニマップ初期化
Sprite_Minimap.prototype.initialize = function() {
    this._size          = 4;
    this._posX          = Graphics.boxWidth / 1.5;
    this._posY          = Graphics.boxHeight / 3;
    this._tileColor     = 'rgba(0, 255, 0, 0.5)';
    this._playerColor   = 'rgba(0, 0, 255, 0.5)';
    this._playerPos     = {x:0, y:0};
    this._bitmapRooms   = [];
    this._bitmapPasses  = [];
    this._spriteset     = new Sprite();
    this.updateMinimap();
};

Sprite_Minimap.prototype.updateMinimap = function() {
this.bitmap = new Bitmap(Graphics.boxWidth, Graphics.boxHeight);
this.showMinimap($gamePlayer.x, $gamePlayer.y);
};

//部屋のミニマップを生成 bitmapRooms配列にビットマップを保存
Sprite_Minimap.prototype.generateMinimapRooms = function(index) {
    if ($gameMap.mapGenerator() instanceof Game_MapGenerator) {
        var rooms = $gameMap.mapGenerator()._rooms;
        this._minimap.fillRect(rooms[index].x * this._size, rooms[index].y * this._size,
                               rooms[index].w * this._size, rooms[index].h * this._size,
                               this._tileColor
                               );
    }
};

//通路のミニマップを生成 bitmapPasses配列にビットマップを保存
Sprite_Minimap.prototype.generateMinimapPasses = function(index) {
    if ($gameMap.mapGenerator() instanceof Game_MapGenerator) {
        var passes = $gameMap.mapGenerator()._passes;
        this._minimap.fillRect(passes[index].x * this._size, passes[index].y * this._size,
                               passes[index].w * this._size, passes[index].h * this._size,
                               this._tileColor
                               );
    }
};

//プレイヤーの現在位置を更新
Sprite_Minimap.prototype.updatePlayerPosition = function() {
    this._playerPos.x = Math.round($gamePlayer.x);
    this._playerPos.y = Math.round($gamePlayer.y);
};

//x, y座標から部屋/通路を求め
Sprite_Minimap.prototype.showMinimap = function(x, y) {
    if ($gameMap.mapGenerator() instanceof Game_MapGenerator) {
        x = Math.round(x);
        y = Math.round(y);
        switch ($gameMap.mapGenerator()._symbolMap[x][y]) {
            case 'room':
                var currentRoom = $gameMap.mapGenerator()._rooms.filter((room, index) => {
                if(room.x <= x && x < room.x + room.w &&
                   room.y <= y && y < room.y + room.h)
                {
                    this.generateMinimapRooms(index);
                }});
                break;
            case 'pass':
                $gameMap.mapGenerator()._passes.filter((pass, index) => {
                if(pass.x <= x && x < pass.x + pass.w &&
                   pass.y <= y && y < pass.y + pass.h)
                {
                    this.generateMinimapPasses(index);
                }});
                break;
        }
    }
};

//マップより上にミニマップを表示

var _Spriteset_Minimap_createUpperLayer = Spriteset_Map.prototype.createUpperLayer
Spriteset_Map.prototype.createUpperLayer = function() {
    _Spriteset_Minimap_createUpperLayer.call(this);
    //this.addChild($gameMap.mapGenerator()._minimap);
}
/*
Spriteset_Map.prototype.createMinimap = function() {
    if ($gameMap.mapGenerator() instanceof Game_MapGenerator &&
        this instanceof Spriteset_Map)
    {
        this._minimap = new Sprite_Minimap();

        this._minimap = $gameMap.mapGenerator()._minimap;
        var sprite = new Sprite_Minimap();
        var x = $gamePlayer.x;
        var y = $gamePlayer.y;
        sprite.bitmap = this._minimap.showMinimap(x, y);
        this.addChild(sprite);
    }
};
*/
//移動するごとにミニマップを更新、踏破済みの部屋/通路を表示するようにする
var _Game_Player_increaseSteps = Game_Player.prototype.increaseSteps;
Game_Player.prototype.increaseSteps = function() {
    _Game_Player_increaseSteps.call(this);
    console.log($gameMap.mapGenerator()._minimap)
   // $gameMap.mapGenerator()._minimap.updateMinimap;
};

コード: 全て選択

this.bitmap = new Bitmap(Graphics.boxWidth, Graphics.boxHeight);



とその関連をコメントアウトするとエラーが発生しなくなるので、この部分でエラーが発生していると思われます。
以下エラーです
TypeError: Cannot set property 'width' of undefined
at Sprite_Minimap.Sprite._onBitmapLoad (rpg_core.js:4167)
at Bitmap.addLoadListener (rpg_core.js:1513)
at Sprite_Minimap.set (rpg_core.js:4000)
at Sprite_Minimap.updateMinimap (SAN_MapGenerator.js:834)
at Sprite_Minimap.initialize (SAN_MapGenerator.js:830)
at new Sprite_Minimap (SAN_MapGenerator.js:813)
at Game_MapGeneratorRoomAndPass.Game_MapGenerator.generateMinimap (SAN_MapGenerator.js:791)
at Game_MapGeneratorRoomAndPass.Game_MapGenerator.setup (SAN_MapGenerator.js:256)
at Game_Map.generateMap (SAN_MapGenerator.js:1293)
at Game_Interpreter.pluginCommand (SAN_MapGenerator.js:1386)

アバター
剣崎 宗二
記事: 681
登録日時: 2016年11月12日(土) 20:36
連絡を取る:

Re: new Bitmapのエラー

投稿記事by 剣崎 宗二 » 2023年11月06日(月) 01:02

Sprite_Minimap.prototype.initializeに問題があります。

Sprite_Battler.prototype.initialize等を参照し、最初にベースクラスのinitialize

コード: 全て選択

Sprite_Base.prototype.initialize.call(this);

を呼び出してください。


エラー自体は上記が実行されていないが故に_frameが初期化されなかった事による連鎖反応です。
rpg_core内のこの行

コード: 全て選択

this._frame.width = this._bitmap.width;

に於いてthis._frameがundefinedである事からこのエラーが出てます。
----
-出先に居る場合回答が未テスト状態である事が多い為、テストは重々にお願いいたします。
-基本自分や友人の問題解決は自分で1からプラグインを書いているので、「こういうプラグインはありますか」に対しては助けになれません。ご了承ください。
ppp
記事: 43
登録日時: 2022年9月28日(水) 21:50

Re: new Bitmapのエラー

投稿記事by ppp » 2023年11月06日(月) 01:56

おかげさまで解決しました!ありがとうございます

“MV:質問” へ戻る