ページ 11

【解決】fillRectについて教えてください。

Posted: 2016年10月15日(土) 19:54
by ビービー
UIを色々変えたくてfillRectを使ってみようと思ったんですがうまくいきません・・・
ご助言おねがいします。

とりあえず今詰まっているところが二点あるのでそれを教えていただければ幸いです。

まずは私がどうしたいかが、わかっていただくだめに画像を見てください。
image_20161015_190242.jpeg
パーティーコマンドとステータスウィンドウにそれぞれfillRectで四角形を書いています。
まずはパーティーコマンドですが、なぜかコマンドが表示されなくなってしまっています。
どうすれば表示されるようになるでしょうか?
↓パーティーコマンドのコード

コード: 全て選択

Window_PartyCommand.prototype.drawItem = function() {
    this.contents.paintOpacity = 64;
    this.contents.fillRect(1, 1, 154, 35, this.textColor(0));
    this.contents.paintOpacity = 255;
};
そしてもう一点、ステータスウィンドウの方ですが、なぜか上のキャラほど文字が薄くなってしまっています。
出来れば四角形を文字の後ろに表示させたいのですがどうすればいいでしょうか?
↓ステータスウィンドウのコード

コード: 全て選択

Window_BattleStatus.prototype.drawBasicArea = function(rect, actor) {
    if ($gameParty.size() == 1) {
        this.contents.paintOpacity = 64;
        this.contents.fillRect(1, 1, 590, 35, this.textColor(0));
        this.contents.paintOpacity = 255;
    } else if ($gameParty.size() == 2) {
            this.contents.paintOpacity = 64;
            this.contents.fillRect(1, 2, 590, 34, this.textColor(0));
            this.contents.fillRect(1, 38, 590, 34, this.textColor(0));
            this.contents.paintOpacity = 255;
        } else if ($gameParty.size() == 3) {
                this.contents.paintOpacity = 64;
                this.contents.fillRect(1, 2, 590, 34, this.textColor(0));
                this.contents.fillRect(1, 38, 590, 34, this.textColor(0));
                this.contents.fillRect(1, 74, 590, 34, this.textColor(0));
                this.contents.paintOpacity = 255;
            } else {
                    this.contents.paintOpacity = 64;
                    this.contents.fillRect(1, 2, 590, 34, this.textColor(0));
                    this.contents.fillRect(1, 38, 590, 34, this.textColor(0));
                    this.contents.fillRect(1, 74, 590, 34, this.textColor(0));
                    this.contents.fillRect(1, 110, 590, 34, this.textColor(0));
                    this.contents.paintOpacity = 255;
            }
    this.drawActorName(actor, rect.x + 0, rect.y, 150);
    this.drawActorIcons(actor, rect.x + 156, rect.y, rect.width - 156);
};
どちらか片方でも教えていただけるとありがたいです。
よろしくお願いします。

Re: fillRectについて教えてください。

Posted: 2016年10月15日(土) 21:06
by 奏ねこま
まずパーティーコマンドのほう。
パーティーコマンドは、Window_PartyCommandの元になっているWindow_CommandのdrawItem関数で描画しています。
それが、Window_PartyCommand.prototype.drawItemを作ったことで上書きされてしまっています。
Window_PartyCommand.prototype.drawItemの中で、元のWindow_Command.prototype.drawItemを呼ぶようにしてください。
drawItem関数の引数も、Window_Command.prototype.drawItemのものに合わせてください。

コード: 全て選択

Window_PartyCommand.prototype.drawItem = function(index) {
    this.contents.paintOpacity = 64;
    this.contents.fillRect(1, 1, 154, 35, this.textColor(0));
    this.contents.paintOpacity = 255;
    Window_Command.prototype.drawItem.call(this, index);
};
次にステータスウインドウですが。
drawBasicAreaはアクターごとに呼ばれる関数です。
なのに1回呼ばれるごとに、パーティーメンバー全員分の背景を描画するようにしているのでおかしな挙動になっているのだと思われます。
それを踏まえて作り直してみてください。

Re: fillRectについて教えてください。

Posted: 2016年10月15日(土) 22:36
by ビービー
奏ねこま(@こま)さん
返信ありがとうごさいます。

パーティコマンドの上にWindow_Commandというものがあったのですね!
ちょうど全部のコマンドに■を描画したかったので、こちらに

コード: 全て選択

Window_Command.prototype.drawItem = function(index) {
    var rect = this.itemRectForText(index);
    var align = this.itemTextAlign();
    this.resetTextColor();
    this.changePaintOpacity(this.isCommandEnabled(index));
    this.contents.paintOpacity = 64;
    this.contents.fillRect(rect.x - 5, rect.y + 2, rect.width + 10, 32, this.textColor(0));
    this.contents.paintOpacity = 255;
    this.drawText(this.commandName(index), rect.x, rect.y, rect.width, align);
};
とやってみたところ望む形になってくれました。
他のウィンドウをいじる手間も省けて思わぬ誤算でした。ありがとうございます。


次にステータスウィンドウですが、他の場所で一回しか呼ばれないところにてきとうに入れてみればいいのかなと思い、色々なとこに入れてみたところ

コード: 全て選択

Window_BattleStatus.prototype.refresh = function() {
    this.contents.clear();
    this.drawAllItems();
    if ($gameParty.size() == 1) {
        this.contents.paintOpacity = 64;
        this.contents.fillRect(1, 1, 590, 35, this.textColor(0));
        this.contents.paintOpacity = 255;
    } else if ($gameParty.size() == 2) {
            this.contents.paintOpacity = 64;
            this.contents.fillRect(1, 2, 590, 34, this.textColor(0));
            this.contents.fillRect(1, 38, 590, 34, this.textColor(0));
            this.contents.paintOpacity = 255;
        } else if ($gameParty.size() == 3) {
                this.contents.paintOpacity = 64;
                this.contents.fillRect(1, 2, 590, 34, this.textColor(0));
                this.contents.fillRect(1, 38, 590, 34, this.textColor(0));
                this.contents.fillRect(1, 74, 590, 34, this.textColor(0));
                this.contents.paintOpacity = 255;
            } else {
                    this.contents.paintOpacity = 64;
                    this.contents.fillRect(1, 2, 590, 34, this.textColor(0));
                    this.contents.fillRect(1, 38, 590, 34, this.textColor(0));
                    this.contents.fillRect(1, 74, 590, 34, this.textColor(0));
                    this.contents.fillRect(1, 110, 590, 34, this.textColor(0));
                    this.contents.paintOpacity = 255;
            }
};
ここに入れたときに理想に近い形で描画されていました。
しかしやはり文字より上に表示されてしまっています。
前回のように上の方が薄いという感じではないのでまだましなのですが、どうにか文字より下に描画する方法はありませんでしょうか?
よろしくお願いします。

Re: fillRectについて教えてください。

Posted: 2016年10月16日(日) 05:17
by ビービー
またいじっていたら解決しました。すみません。
this.drawAllItems();
の下にコードを書いていたのを、上にコピペするだけで解決してしまいました。
よく調べもせず質問してしまい申し訳ありませんでした。

これにて解決とさせていただきます。