Home‎ > ‎Unit 04‎ > ‎

Mouse Click

In this less we'll learn how to use the buttons on the mouse rather than just see where it is. Watch the video below and read pages 60-64 of Getting Started with Processing. This will get you started.

New Code
  • mousePressed - This is a boolean variable. It can be true or false. When true it stores the button pressed into the mouseButton.
  • mouseButton - When a button is pressed the state of mouseButton is changed to LEFT, RIGHT, or CENTER to reflect the button pressed.
  • if (statement) - This ask a question. if true the code in the following curly braces is executed.
  • else if (statement) - This can follow an if and will be used if the initial if is false. Otherwise it behaves as an if.
  • else - This can follow an if or else if. The code in the curly braces after the else will be executed when the preceding if  or else if is false.
Read through the pages 64-68 on determining location and try out all the code examples.

Assignment 4.4 - Take the silly face you made for Assignment 4.3. Change the code so that the eyes only follow the cursor when the mouse is on the face and make the eyes blink when they are clicked on.

Assignment 4.5 -  Modify your code form Assignment 3.2 so that your robot follows your mouse (see pg. 74 for an example). Be sure to include easing so its motion won't be so jarring. Also make something happen when a mouse button is pressed.
Comments