Scratch for Java

Sprite::whenMouseMoved(x, y)

This method is called when the mouse cursor is moved. The method will receive the x and y position of the mouse as paramters.

Examples

import org.openpatch.scratch.Sprite;
import org.openpatch.scratch.Stage;

public class SpriteWhenMouseMoved {

  class CustomSprite extends Sprite {

    public CustomSprite() {
      this.addCostume("zeta", "assets/zeta_green_badge.png");
      this.addCostume("gamma", "assets/gamma_purple_badge.png");
    }

    @Override
    public void whenMouseMoved(double x, double y) {
      this.setPosition(x, y);
    }
  }

  public SpriteWhenMouseMoved() {
    Stage myStage = new Stage(600, 240);
    myStage.add(new CustomSprite());
    while (myStage.getTimer().forMillis(3000)) {}
    myStage.exit();
  }

  public static void main(String[] args) {
    new SpriteWhenMouseMoved();
  }
}

View on GitHub

Syntax

Java

void whenMouseMoved(x, y)

Scratch

Parameters

NameData TypeDescription
xfloatThe x coordinate of the mouse cursor
yfloatThe y coordinate of the mouse cursor

Return

void