Archived

This topic is now archived and is closed to further replies.

Tac-Tics

[java] I can't get my custom cursor the right size

Recommended Posts

Tac-Tics    197
Iwas trying to experiment with a custom cursor for my game. I made my jpg file (10x10 pixels), then loaded it as an Image object. Then I called the createCustomCursor method of toolkit and called the setCursor function of my frame. It displays the new icon for the mouse, but it''s very clearly more than 10x10 pixels in size. Can anyone help me with this? Here''s the code I used for it. ------------------------------------------------- Toolkit tool = Toolkit.getDefaultToolkit(); Image cursorImage = tool.getImage("crosshairs.jpg"); Point p = new Point(5, 5); Cursor aimCursor = tool.createCustomCursor(cursorImage, p, "aimCursor"); setCursor(aimCursor); ------------------------------------------------- "I''''m not evil... I just use the power of good in evil ways."

Share this post


Link to post
Share on other sites
CaptainJester    523
From what I understand reading one of the ToolKit cursor functions, not all sizes are supported. Look at this function from the ToolKit:

getBestCursorSize
public Dimension getBestCursorSize(int preferredWidth,
int preferredHeight)
Returns the supported cursor dimension which is closest to the desired sizes. Systems which only support a single cursor size will return that size regardless of the desired sizes. Systems which don''t support custom cursors will return a dimension of 0, 0.
Note: if an image is used whose dimensions don''t match a supported size (as returned by this method), the Toolkit implementation will attempt to resize the image to a supported size. Since converting low-resolution images is difficult, no guarantees are made as to the quality of a cursor image which isn''t a supported size. It is therefore recommended that this method be called and an appropriate image used so no image conversion is made.

Parameters:
desiredWidth - the preferred cursor width the component would like to use.
desiredHeight - the preferred cursor height the component would like to use.
Returns:
the closest matching supported cursor size, or a dimension of 0,0 if the Toolkit implementation doesn''t support custom cursors.
Since:
1.2


---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home

Share this post


Link to post
Share on other sites
Tac-Tics    197
It returns a dimension of 32x32 pixels as the smallest size, which seems rediculously big for a cursor =-/ I guess the mouse can wait until the rest of the game is done.

"I''''m not evil... I just use the power of good in evil ways."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Forgive my ignorance, for i''m pretty new to Java, but can''t you just use a 32x32 image for a cursor, put your image in the upper left 10x10 of it, and set the rest as transparent?

Share this post


Link to post
Share on other sites
Idej-Avaj    122
Probably, but the question to ask after that is wether or not it would slow the performance of the game any. It''d be a waste to have a custom cursor, but to have the speed take a hit.

Share this post


Link to post
Share on other sites
javanerd    122
I did some research on this subject for my GF4J game library and noted that under JDK 1.2, 1.3 and 1.4 you take a small (but visible) speed hit when using custom cursors. You should just try it and see is the speed hit too much for your game.

Also the method getBestCursorSize() returns the size 32x32 on Windows 98/ME/NT/2000, Linux and Solaris. So you could assume that 32x32 cursor works on all platforms.

Share this post


Link to post
Share on other sites