How to make an object move wherever your mouse moves -- Greenfoot programming
Find other posts in the same category: |

Contents

This is covered in the video tutorial on accepting mouse input.

http://www.greenfoot.org/videos/mouseInteraction.mov

http://www.greenfoot.org/doc/videos.html

Here is the code you use.

public class Smiley extends Actor
{
public void act()
{
if (Greenfoot.mouseMoved(null) ) {
MouseInfo mouse = Greenfoot.getMouseInfo();
setLocation (mouse.getX(), mouse.getY());
}
}
}


Next Book Page

To see posts on the same topic, click the links below the name of the author at the top of this page.