1

Slick でヘルスバーをレンダリングしようとしています。残りの健康状態を示すために、赤い四角形とその前に緑の四角形が必要です。これは私がこれまでに持っているものです:

        Rectangle healthBG = new Rectangle(healthX, healthY, healthWidth, healthHeight);
        ShapeFill healthFill = new GradientFill(0, healthHeight / 2, Color.red, healthWidth, healthHeight - 1, Color.orange, true);

        float healthGAWidth = ((float) health / (float) maxHealth) * (float) healthWidth;
        Rectangle healthGA = new Rectangle(healthX, healthY, healthGAWidth, healthHeight);
        ShapeFill healthGAFill = new GradientFill(0, healthHeight / 2, Color.green, healthGAWidth, healthHeight - 1, Color.green, true);

        //g.setColor(Color.red);
        g.draw(healthBG, healthFill);
        //g.setColor(Color.green);
        g.draw(healthGA, healthGAFill);

これは、画面にレンダリングされるものです。

動作中のヘルスバーのスクリーンショット

4

1 に答える 1

2

問題は、間違ったレンダリング方法を使用していることです。Graphics には、draw() と fill() の 2 種類のメソッドがあります。レンダリング ラインは次のようになります。

g.fill(healthBG, healthFill);

または、Graphics には四角形を塗りつぶすメソッドがあるため、Rectangle または ShapeFill の作成をスキップすることもできます。

float healthGAWidth = ((float) health / (float) maxHealth) * (float) healthWidth;
g.fillRect(healthX, healthY, healthWidth, healthHeight);
g.fillRect(healthX, healthY, healthGAWidth, healthHeight);
于 2012-07-26T19:54:52.970 に答える