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

2017/6/29

Answer2

Venbha Venbha

2017/6/29

#
Hello its me again this is one more code
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo etc)
 
public class Object extends Actor
{
    public void act() 
    {
        MouseInfo pointer = Greenfoot.getMouseInfo();
        if(pointer != null)
        {
            int mouseX = pointer.getX();
            int mouseY = pointer.getY();
            turnTowards(mouseX, mouseY);
            move(10);
        }
    }    
}
ok now it will point and move. or else if you want to make it move when clicked in background, see Here.
You need to login to post a reply.