Crosshairs in Java

Posted by typoknig on Stack Overflow See other posts from Stack Overflow or by typoknig
Published on 2010-03-16T05:47:06Z Indexed on 2010/03/16 5:56 UTC
Read the original article Hit count: 318

Filed under:
|
|

I am making a game that needs a crosshair. I have been playing with the java.awt.cursor class and that is easy enough, but the problem is that I do not want the crosshairs to be able to leave the window I create for my game, so I tried this instead:

  private void drawCrossHair(Graphics g){
    Ellipse2D ellipse = new Ellipse2D.Float();
    ellipse.setFrame(crossHair.x, crossHair.y, 36, 36);
    Color yellow = new Color (0xEDFF62);
    g.setColor(yellow);            
    g.fillOval(crossHair.x, crossHair.y, 40, 40);
    g.setClip(ellipse);
    g.clip(ellipse);

Basically I am trying to remove the "ellipse" from "g" leaving only a small ring behind. The problem here is that "g.clip(ellipse);" gives me an error. My objective with this code is to create a circle with a transparent center, like a donut. Once the donut is created I will add some small points on the inside of it so it looks more like crosshairs. One thing that may or may not be an issue is that I plan on moving the crosshairs with a joystick, not a mouse... I do not know if that will limit my options for what kind of object my crosshairs can be.

© Stack Overflow or respective owner

Related posts about java

Related posts about cursor