P.16 (Image to Show the Key Down)


// This method is called whenever
// the "Act' or 'Run' button gets
// pressed in the environment

public void act() {
  // Check if key "g" is pressed
  if(Greenfoot.isKeyDown ("g")) {
    // change to gray image
    setImage("white-key-down.png");
  }
  else {
    // change to original image, i.e. white
    setImage("white-key.png");
  }
}
Last modified on
Engineering DIY Workshop 2018