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

2017/12/25

How to make Greenfoot Left click when "C" is pressed

Rexsan Rexsan

2017/12/25

#
Currently I have everything ready except for the clicking which I do not know how to mock
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * Write a description of class Clicker here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Clicker extends Actor
{
    /**
     * Act - do whatever the Clicker wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        Click();
    }

    private void Click()
    {
        if (Greenfoot.isKeyDown("c") ){
            Greenfoot.delay(Greenfoot.getRandomNumber(15) - 5);
            Greenfoot.playSound("Click.mp3");
            // here put mock click
        }
    }  
}
xbLank xbLank

2017/12/25

#
May I ask what the point of that is? Cus I dont really understand why you want to make Greenfoot click. Are you sure you dont want to check if the user has clicked an Actor?
danpost danpost

2017/12/25

#
More than where to put 'Greenfoot.mouseClicked(this)', wihich should be ANDed, using '&&", at line 21, is what to use in the 'delay' parameter, which should not be less than one (or rather should not be used at all and a timer should be introduced).
You need to login to post a reply.