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

2015/10/30

Mouse Click

pleasehelpme pleasehelpme

2015/10/30

#
i need help with the ff instructions :(((( After clicking Run, the actor should be still The object should turn/face, move to, and stop at wherever the mouse is left-clicked in the world (left-click only) After stopping, the object should maintain its direction.
danpost danpost

2015/10/30

#
What part of this are you having problems with? What have you tried? Hint: to start, your actor will need to hold, at minimum, the location coordinates that it will move to. These can initially be set to the location at which it is placed into the world.
pleasehelpme pleasehelpme

2015/11/3

#
i have this so far but i the actor won't continuously move to the location where i clicked
1
2
3
4
5
6
7
8
9
10
11
public void act()
{
     
    
    MouseInfo mouse = Greenfoot.getMouseInfo();
    if (Greenfoot.mouseClicked(null) && mouse.getButton()==1 )
    {
        move(10);
        this.turnTowards(mouse.getX(),mouse.getY());
 
    }
danpost danpost

2015/11/3

#
You put the condition that the left mouse button be clicked for the actor to move and turn. That is, each time a click is registered, you have a move and turn executed. What that condition should be controlling is the setting up of a move to the clicked location, which may include turning -- but, not moving. Different conditions are to control the moving. Something that determines whether you are at the clicked location or not.
You need to login to post a reply.