Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problems with Custom Cursor in Shooting Game  (Read 4534 times)
0 Members and 1 Guest are viewing this topic.
Offline vivek.yadav.727

Junior Newbie

« Posted 2012-08-15 16:44:02 »

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.setTitle("Sniper Frame");

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image cursorImage = toolkit.getImage("MilDotScope.png");
    Point cursorHotSpot = new Point(0,0);
    Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "Cursor");
  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. Sad

Offline Jimmt
« League of Dukes »

JGO Kernel

Medals: 167
Projects: 5
Exp: 6 years

« Reply #1 - Posted 2012-08-15 17:09:05 »

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.
Offline Vladiedoo
« Reply #2 - Posted 2012-08-15 17:26:35 »

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");

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  Grin.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vivek.yadav.727

Junior Newbie

« Reply #3 - Posted 2012-08-15 18:07:27 »

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..??
Offline vivek.yadav.727

Junior Newbie

« Reply #4 - Posted 2012-08-15 18:20:33 »

and Vladiedoo,

we cant use paint(graphics g) method in JFrames / JPanels or can we..??
Offline Vladiedoo
« Reply #5 - Posted 2012-08-15 19:25:41 »

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.
Offline Nate

« JGO Bitwise Duke »

Medals: 167
Projects: 4
Exp: 14 years

Esoteric Software

« Reply #6 - Posted 2012-08-15 19:34:11 »

What the hell is going on in that picture?

Offline Vladiedoo
« Reply #7 - Posted 2012-08-15 19:35:17 »

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.
Offline h3ckboy

JGO Coder

Medals: 5

« Reply #8 - Posted 2012-08-15 19:51:25 »

What the hell is going on in that picture?
dangit, I didn't see that until you pointed it out...
Offline vivek.yadav.727

Junior Newbie

« Reply #9 - Posted 2012-08-16 15:59:03 »

plzz.. guys u were helping me out.. thanks Smiley
Pages: [1]
  ignore  |  Print  

EgonOlsen (42 views)
2018-06-10 19:43:48

EgonOlsen (22 views)
2018-06-10 19:43:44

EgonOlsen (43 views)
2018-06-10 19:43:20

DesertCoockie (198 views)
2018-05-13 18:23:11

nelsongames (124 views)
2018-04-24 18:15:36

nelsongames (123 views)
2018-04-24 18:14:32

ivj94 (864 views)
2018-03-24 14:47:39

ivj94 (125 views)
2018-03-24 14:46:31

ivj94 (768 views)
2018-03-24 14:43:53

Solater (140 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!