public class MousePointer extends GameFigure {
public final int SIZE = 10;
public MousePointer(int x, int y){
super(x,y);
}
@Override
public void render(Graphics2D g2) {
g2.setColor(Color.CYAN);
g2.drawLine((int)location.x - SIZE,(int) location.y,
(int) location.x + SIZE, (int)location.y);
g2.drawLine((int)location.x, (int)location.y - SIZE,
(int)location.x,(int)location.y + SIZE);
g2.drawOval((int)location.x - SIZE,(int)location.y - SIZE,(int)location.x-SIZE,(int)location.y - SIZE);
}
@Override
public void update() {
// NA/
}
@Override
public int getCollisionRadius() {
return 0;
}
}
我正在尝试为游戏创建像狙击手的图像,但它不允许我这样做。它的显示方式:
即使我移动鼠标时我也希望它看起来像:
您正在做的就是告诉您想要真正称呼它的椭圆或椭圆左上角的java x和y位置。基本Java没有中心翻译功能,您需要自己计算椭圆的width / 2和height / 2。
替换
g2.drawOval((int)location.x - SIZE,(int)location.y - SIZE,(int)location.x-SIZE,(int)location.y - SIZE);
with
g2.drawOval((int)location.x - SIZE,(int)location.y - SIZE,SIZE,SIZE);