[java] Custom mouse cursors in games
Is there a way to have the standard cursor disapear so I could handle it myself by taking the x,y corrdinates from a mouse listener for bliting my own cursor image during my graphic engine loop ? I mean when in fullscreen mode (but not necessarily), I would like to have custom animated 256+ colors cursors changing with the coordinates to reflect what actions the user may perform. For example, think of an isometric game (starcraft-like RTS or bladur-like RPG).
Also, I would like to know if this could speed up graphics in some way because the standard cursor would not be blitted to screen by the JVM or the OS in a separate graphic loop.
I am currently using the GameFrame engine so if someone knows of such a feature in this engine, it''s great. Anyway, I am considering any advice regarding the subject as it is, for me, an important feature of the game I plan (staying with standard cursor makes games, well... not looking "pro").
Herve
Good-day;
I'm not sure about the "GameFrame" engine, but here is way to create a custom cursor (this is the way I do it
):
In your applet or application (in the class that extends an awt/swing Container ie (J)Applet,(J)Frame etc) do this:
Cursor myCursor
= Toolkit.getDefaultToolkit().createCustomCursor(
Image cursor, Point hotSpot,String name)
- this method also throws an IndexOutOfBoundsException, so catch it.
// in you applet or app
setCursor(myCursor);
// that's it.
(keep in mind that above I just showed the prototype of the method
)
For more info on this method goto:
Sun's Toolkit Doc
Cheers,
JP.
==============================================
I feel like a kid in some kind of store...
==============================================
www.thejpsystem.com
Edited by - loserkid on August 20, 2001 4:00:44 PM
I'm not sure about the "GameFrame" engine, but here is way to create a custom cursor (this is the way I do it

In your applet or application (in the class that extends an awt/swing Container ie (J)Applet,(J)Frame etc) do this:
Cursor myCursor
= Toolkit.getDefaultToolkit().createCustomCursor(
Image cursor, Point hotSpot,String name)
- this method also throws an IndexOutOfBoundsException, so catch it.
// in you applet or app
setCursor(myCursor);
// that's it.
(keep in mind that above I just showed the prototype of the method

For more info on this method goto:
Sun's Toolkit Doc
Cheers,
JP.
==============================================
I feel like a kid in some kind of store...
==============================================
www.thejpsystem.com
Edited by - loserkid on August 20, 2001 4:00:44 PM
==============================================I feel like a kid in some kind of store... ============================================== www.thejpsystem.com
Hi!
If you use the technique proposed by loserkid, I have an extra tip.
You could divide the screen (or window) into several panels. For example, a mainpanel for the isometric stuff and one panel which contains controls etc. You could the set one cursor for each panel. When you move from one panel to the other the mousepointer automatically shift the cursor.
Regards
Johan
If you use the technique proposed by loserkid, I have an extra tip.
You could divide the screen (or window) into several panels. For example, a mainpanel for the isometric stuff and one panel which contains controls etc. You could the set one cursor for each panel. When you move from one panel to the other the mousepointer automatically shift the cursor.
Regards
Johan
Johan Karlsson
In GF4J''s GraphicsEngine you can do this, but after that you can''t run your game on pre-JDK 1.2 runtimes. So I''d be good practise to check the runtime version on game startup and throw a message to the user about him having too old JDK version. I''ve thought about adding support for this in GF4J itself, but as it can''t be made to work in JDK 1.1 I''ve yet to decide what to do...
-
JavaNerd
javanerd at geocities dot com
-
JavaNerd
javanerd at geocities dot com
-Pasi Keranen
ok so maybe I could just set the cursor to null and then print my own cursor the way I want in my own graphic loop by using the mouse coordinates (which I can get in GF4J with PointerDevice.getX() and getY()). But when in fullscreen mode, how do I setCursor() ? because setCursor() is a method of java.awt.Component and I don''t know exactly if the fullscreen mode can be managed as a component. In fact, I do admit I don''t known anything about fullscreen mode in JDK 1.4 as I was using GF4J before the release of 1.4 and I am too lazy to re-code the whole thing now. GF4J is so useful when JDK upgrades and you just want to benefit from the new features without re-thinking your stuff.
Herve
Herve
This can be done like this (a bit ugly, but I''ll try to solve this problem in 0.9.6):
-
JavaNerd
javanerd at geocities dot com
GraphicsEngine grfxEngine = GameFrame.getGraphicsEngine();if( grfxEngine instanceof java.awt.Component ){ ( (Component) grfxEngine ).setCursor( myCursor );}
-
JavaNerd
javanerd at geocities dot com
-Pasi Keranen
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement