mouseDidMove()

Category:Game Lab

Checks if the mouse moved.

Some interactive games use the mouse for the user to control the game.

Examples

var count=0;
function draw() {
  background("white");
  if (mouseDidMove()) {
    count=count+1;
  }
  text("count="+count, 0, 15);
}

                            // Keep the sprite up by moving the mouse over the sprite.
var sprite = createSprite(200, 200,25,25);
function draw() {
  background("white");
  if (mouseIsOver(sprite) && mouseDidMove()) {
    sprite.y=sprite.y-1;
  } else {
    sprite.y=sprite.y+1;
  }
  drawSprites();
}
                        

Syntax

mouseDidMove()

Returns

Boolean true or false.

Tips

  • When testing your games that use keyboard or mouse input make sure you click in the display area before you run, otherwise the Workspace will record your keyboard and mouse actions.

Found a bug in the documentation? Let us know at documentation@code.org