Problems with Custom Cursor in Shooting Game

Hey guys!!
I’m having trouble with having a custom Cursor in shape of a Sniper scope reticle…
what i want is that the the crosshair of the reticle be the mouse pointer but all i get is a small image about 15px X 15px with the top left corner as the mouse pointer…

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class SniperCursor
{
  public SniperCursor()
  {
    JFrame myFrame = new JFrame();
    myFrame.setSize(400,400);
    myFrame.setTitle("Sniper Frame");
    myFrame.setVisible(true);
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image cursorImage = toolkit.getImage("MilDotScope.png");
    Point cursorHotSpot = new Point(0,0);
    Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "Cursor");
    myFrame.setCursor(customCursor);
  }
  public static void main (String[] arg)
  {
     SniperCursor myWindow = new SniperCursor();
  }
}

if i cant do what i want this way… is there any other way of doing this… I thought about using MouseMoved() method on a JLabel with the Reticle set as ImageIcon on the JLabel… but it is not performing as required. :frowning:

PLEASE HELP!!

I think it would be easier to use mouseListener. I mean, if it’s a shooting game, you’ll probably have to use it anyways, right?
EDIT: nvm, I see what you’re doing.

I’m still a newbie but consider this…
Change your cursor image to be 16x16 that way the center point can be a whole number.

The following code determines where the mouse pointer is, so instead of (0,0) use (8,8), that way the center of the image will act as the pointer.

Point cursorHotSpot = new Point(0,0);

Another way of solving this is by setting the cursor invisible and just drawing a fake cursor over it.

Toolkit t = Toolkit.getDefaultToolkit();
Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none");
setCursor(noCursor);
g.drawImage(imageManager.getMouseImage(), null, mouseX, mouseY);

For you that last bit of code would be mouseX - 8, mouseY - 8 so you utilize the center of your image.

Edit: Perhaps this topic would also be better in the Newbie & Debugging Questions section.
Oh and welcome to the forums ;D.

sorry i had no idea where to put the question so i put i here.

and how do i insert pics in this post from my desktop??

and i actually have a 2000 x 1400 px pic (for 1000 X 700 px JFrame) in the centre of which is the reticle… i want the targets should only be visible through the reticle… so do i do…

Point cursorHotSpot = new Point(1000,700);

or something else…??

and Vladiedoo,

we cant use paint(graphics g) method in JFrames / JPanels or can we…??

Just tested it out and found out now, to insert a image you first need to have it on the internet, I used TinyPic just now and it worked. When you’re writting your post you click on the tiny “Insert Image” square and it will give you “[ img][/img]”, insert your link between the ][.

Correct and correct, I use a canvas to draw.

What the hell is going on in that picture?

LOL, I never saw it that way, a while ago I asked my friend to make me skill icon for regeneration, it’s un-finished though haha.

dangit, I didn’t see that until you pointed it out…

plzz… guys u were helping me out… thanks :slight_smile: