Skip to content

movedX

A Number system variable that tracks the mouse's horizontal movement.

movedX tracks how many pixels the mouse moves left or right between frames. movedX will have a negative value if the mouse moves left between frames and a positive value if it moves right. movedX can be calculated as mouseX - pmouseX.

Examples

movedX example 1

function setup()
  size(100, 100)

  describe(
    'A gray square. The text ">>" appears when the user moves the mouse to the right. The text "<<" appears when the user moves the mouse to the left.'
  )
end

function draw()
  background(200)
  fill(0)

  -- Style the text.
  textAlign(CENTER)
  textSize(16)

  -- Display >> when movedX is positive and
  -- << when it's negative.
  if movedX > 0 then
    text('>>', 50, 50)
  elseif movedX < 0 then
    text('<<', 50, 50)
  end
end

Syntax

movedX

Returns

Number: positive or negative number tracking horizontal movement.