This site requires JavaScript, please enable it in your browser!
Greenfoot back
PiRocks
PiRocks wrote ...

2011/4/10

Mouse Icon

PiRocks PiRocks

2011/4/10

#
Is it possible to change the mouse's icon if it moves over an Actor? And if so, can you then change it to a system cursor, i.e. the system text cursor, as supposed to just a pre-made image?
architsch architsch

2011/4/17

#
You can create an actor that always follows the mouse cursor. That's one way. You can actually change the cursor, but then you have to use the Cursor class in "java.awt." package.
PiRocks PiRocks

2011/4/17

#
Thanks for your response, but that wasn't what I was exactly looking for. I already looked into java.awt.Cursor before hand and this is the basics - a Cursor is essentially a special kind of image that can be used to replace the mouse's image, however (and this is a big however...) it will only be applied to a specific java.awt.Component. And so you get to my problem - you need to get the actual Component that the World is drawing to in order to change the mouse's image. So I was essentially asking how to get that component.
architsch architsch

2011/4/18

#
Suppose that there is an actor called "monster." The following line will examine if the mouse cursor is on that actor: if(Greenfoot.mouseMoved(Object monster)) { /* Change your mouse cursor */ }
Builderboy2005 Builderboy2005

2011/4/18

#
I think PiRocks was asking how to get access to the applet component that Greenfoot draws onto, not how to tell if the mouse if over an actor o.O Either way, I don't think there is a way to do this in Greenfoot currently, as we need access to the *specific* component of the world that is painted on, and none of the methods available to us give us access. I think this would be an excellent candidate for a new feature request, although I myself am going to hold off after I nagged to hard for volume control :P
davmac davmac

2011/4/18

#
LOL! Builderboy2005, you'll get volume control in the next Greenfoot release (whenever that is). We've implemented it already (Michael Berry did the work). However: I don't think at this stage we'll add the ability to get access to the component the world is drawn on. PiRocks, I have an unofficial method for you, but I don't encourage its use and it might stop working in future Greenfoot versions. Basically:
import greenfoot.core.WorldHandler;

JPanel panel = WorldHandler.getInstance().getWorldCanvas();
... will give you access to the JPanel instance that the world is drawn on.
Builderboy2005 Builderboy2005

2011/4/18

#
Wow that is awesome! I can't wait to use this in my games :D
architsch architsch

2011/4/18

#
Maybe you can simply create a separate window (JFrame or JWindow) and program with it. It works separate from Greenfoot, but it allows you to handle various events...
Builderboy2005 Builderboy2005

2011/4/18

#
I think adding a separate screen would kind of defeat the whole purpose of greenfoot. No matter though, we have what we need to make custom cursors :) I plan on uploading a demo to the gallery in a bit
PiRocks PiRocks

2011/4/19

#
Thanks davmac for the code. I'm glad I didn't have to search through the source like I did for my last major problem (collision detecting outside of the world, this was before Greenfoot 2).
You need to login to post a reply.