【发布时间】:2016-02-15 04:15:14
【问题描述】:
我正在使用鼠标光标制作游戏,我想通过用绿色版本的图像覆盖光标来表示健康,但只有一个几何扇区对应于健康百分比。来自以下帖子的解决方案:Drawing slices of a circle in java? 和 How to draw portions of circles based on percentages in Graphics2D? 几乎是我想做的,但使用 BufferedImage 而不是纯色填充。
//Unfortunately all this does is cause nothing to draw, but commenting this out allows the overlay image to draw
Arc2D.Double clip = new Arc2D.Double(Arc2D.PIE);
double healthAngle = Math.toRadians((((Double)data.get("health")).doubleValue() * 360.0 / 100.0) - 270.0);
clip.setAngles(0, -1, Math.cos(healthAngle), Math.sin(healthAngle));
System.out.println(Math.cos(healthAngle) + " " + Math.sin(healthAngle));
g.setClip(clip);
简而言之,如何在给定任意角度的情况下绘制 BufferedImage 的扇区?
【问题讨论】:
-
您的弧线宽度为零,高度为零。它的 x 和 y 也为零。使用long constructor,它允许您设置它们(也使您不必使用显式三角函数)。
标签: java bufferedimage graphics2d