Search processing.org:

Reference for Processing version 1.0.1+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

### pmouseX

Examples

    // Move the mouse quickly to see the difference
    // between the current and previous position
    void draw()
    {
      background(204);
      line(mouseX, 20, pmouseX, 80);
    }

Description

The system variable pmouseX always contains the horizontal position of the mouse in the frame previous to the current frame.
You may find that pmouseX and pmouseY have different values inside draw() and inside events like mousePressed() and mouseMoved(). This is because they're used for different roles, so don't mix them! Inside draw(), pmouseX and pmouseY update only once per frame (once per trip through your draw()). But, inside mouse events, they update each time the event is called. If they weren't separated, then the mouse would be read only once per frame, making response choppy. If the mouse variables were always updated multiple times per frame, using line(pmouseX, pmouseY, mouseX, mouseY) inside draw() would have lots of gaps, because pmouseX may have changed several times in between the calls to line(). Use pmouseX and pmouseY inside draw() if you want values relative to the previous frame. Use pmouseX and pmouseY inside the mouse functions if you want continuous response.

Syntax

    pmouseX

Usage | Web & Application
Related | pmouseY mouseX mouseY

Updated on November 22, 2008 08:39:25pm PST