ミニマッププラグインの試作

返信する
ppp
記事: 48
登録日時: 2022年9月28日(水) 21:50

ミニマッププラグインの試作

投稿記事 by ppp »

ミニマッププラグインを制作中なのですが、fillRectのwidth, height とBitmapのwidth, heightの違いがわかりません。ご教授いただけるとありがたいです。

コード: 全て選択

/*:
 * @plugindesc ミニマップを表示
 * @author free
 * @help MZ MV ミニマップを表示
 */

(function () {
    "use strict";

    const pluginName = 'MiniMap';

    var _Spriteset_Base_createUpperLayer = Spriteset_Base.prototype.createUpperLayer;
    Spriteset_Base.prototype.createUpperLayer = function() {
        _Spriteset_Base_createUpperLayer.apply(this, arguments);
        if (this instanceof Spriteset_Map) {
            this.createDrawSprite();
        }
    };

    Spriteset_Map.prototype.createDrawSprite = function() {
        var sprite = new Sprite()

        for(var x = 0; x < $dataMap.width; x++){
            for(var y = 0; y < $dataMap.width; y++){
            sprite.bitmap = this.makeDrawBitmap(x, y);
            this.addChild(sprite);
            }
        }
    };

    Spriteset_Map.prototype.makeDrawBitmap = function(x, y) {
        var bitmap = new Bitmap(Graphics.boxWidth, Graphics.boxHeight);
        bitmap.fillRect(x, y, 10, 10,'rgba(255, 255, 255, 0.5)');
        return bitmap;
    };
})();
アバター
Plasma Dark
記事: 736
登録日時: 2020年2月08日(土) 02:29
連絡する:

Re: ミニマッププラグインの試作

投稿記事 by Plasma Dark »

Bitmapのコンストラクタに渡す width, height はcanvasの縦横幅であり、fillRectはcanvasの2Dcontextに対して矩形を描画するメソッドです。

Bitmapクラスは rpg_core.js に定義されているので、その initialize や _createCanvas を読んでみてください。

HTMLCanvasElement: width プロパティ - MDN
CanvasRenderingContext2D - MDN
ppp
記事: 48
登録日時: 2022年9月28日(水) 21:50

Re: ミニマッププラグインの試作

投稿記事 by ppp »

返答ありがとうございます!大変助かりました!
ppp
記事: 48
登録日時: 2022年9月28日(水) 21:50

Re: ミニマッププラグインの試作

投稿記事 by ppp »

再度質問失礼します

コード: 全て選択

/*:
 * @plugindesc ミニマップを表示
 * @author free
 * @help MZ MV ミニマップを表示
 */

(function () {
    "use strict";

    const pluginName = 'MiniMap';

    var _Spriteset_Base_createUpperLayer = Spriteset_Base.prototype.createUpperLayer;
    Spriteset_Base.prototype.createUpperLayer = function() {
        _Spriteset_Base_createUpperLayer.apply(this, arguments);
        if (this instanceof Spriteset_Map) {
            this.createDrawSprite();
        }
    };

    Spriteset_Map.prototype.createDrawSprite = function() {
        var sprite = new Sprite()

        for(var x = 0; x < $dataMap.width; x++){
            for(var y = 0; y < $dataMap.width; y++){
            sprite.bitmap = this.makeDrawBitmap(x, y);
            this.addChild(sprite);
            }
        }
    };

    Spriteset_Map.prototype.makeDrawBitmap = function(x, y) {
        var bitmap = new Bitmap(Graphics.boxWidth, Graphics.boxHeight);
        bitmap.fillRect(x, y, 10, 10,'rgba(255, 255, 255, 0.5)');
        return bitmap;
    };
})()
このプログラムは、とりあえずマップの範囲分だけ矩形を表示しようとしているのですが、うまくいきません。何故でしょうか?教えていただけると幸いです。具体的な問題として、矩形が一つしか表示されません
アバター
Plasma Dark
記事: 736
登録日時: 2020年2月08日(土) 02:29
連絡する:

Re: ミニマッププラグインの試作

投稿記事 by Plasma Dark »

Spriteインスタンスをひとつだけ作って、それを書き換えているだけなのでひとつしか表示されません。
1マス1Spriteで作るより、1Sprite内のBitmapで全マス分の描画を行ってしまうほうが考えることは少なくなりそうです。

ミニマップというくらいなのだから、画面全体と同じ大きさのBitmapを作るのは過剰ですね。適切な大きさに絞ってあげると良いと思います。
fillRectで指定する矩形は、今のコードだとほとんど隣のマスと重なってしまっているようです。
ppp
記事: 48
登録日時: 2022年9月28日(水) 21:50

Re: ミニマッププラグインの試作

投稿記事 by ppp »

気づけず返信おくれてすみません。回答ありがとうございました
返信する

“MV:質問”に戻る