我正在尝试使用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);
这是在屏幕上呈现的内容:
答案 0 :(得分:2)
问题是您使用的是错误的渲染方法。在Graphics中有两种类型的方法draw()和fill()。您的渲染线应为:
g.fill(healthBG, healthFill);
或者你可以跳过制作一个Rectangle或ShapeFill,因为Graphics有一个填充矩形的方法:
float healthGAWidth = ((float) health / (float) maxHealth) * (float) healthWidth;
g.fillRect(healthX, healthY, healthWidth, healthHeight);
g.fillRect(healthX, healthY, healthGAWidth, healthHeight);