Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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 2287 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..

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
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. Sad

PLEASE HELP!!
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 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.
1  
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.
1  
2  
3  
4  
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);

1  
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..

1  
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 Kernel


Medals: 149
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (46 views)
2014-10-17 03:59:02

Norakomi (37 views)
2014-10-16 15:22:06

Norakomi (28 views)
2014-10-16 15:20:20

lcass (32 views)
2014-10-15 16:18:58

TehJavaDev (62 views)
2014-10-14 00:39:48

TehJavaDev (62 views)
2014-10-14 00:35:47

TehJavaDev (52 views)
2014-10-14 00:32:37

BurntPizza (70 views)
2014-10-11 23:24:42

BurntPizza (40 views)
2014-10-11 23:10:45

BurntPizza (82 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!