Greenfoot.getMouseInfo() can return null. When it does, your 'mouse' variable will contain null, and then
mouse.getX()
fails with a NullPointerException, because you have no 'mouse' object.
In general, you should call getMouseInfo after a mouse event, such as mouseClicked.
Greenfoot.getMouseInfo() can return null. When it does, your 'mouse' variable will contain null, and then
mouse.getX()
fails with a NullPointerException, because you have no 'mouse' object.
In general, you should call getMouseInfo after a mouse event, such as mouseClicked.
Thank you! Now I undersdand!
Another question about mouse event, how can I find out if the mouse is hold on sth.
I tried to figgure it out by getX() and getY(),is there some good iead?Thanks