Scratch for Java

Sprite::distanceToMousePointer()

Returns the distance to the mouse pointer.

Examples

import org.openpatch.scratch.*;
 
public class SpriteDistanceToMousePointer {
  public SpriteDistanceToMousePointer() {
    Stage myStage = new Stage(600, 240);
 
    Sprite gamma = new Sprite("gamma", "assets/gamma_purple_badge.png");
    gamma.setPosition(0, 50);
    myStage.add(gamma);
 
    while (myStage.getTimer().forMillis(3000)) {
      gamma.changeX(5);
      myStage.display("Distance: " + gamma.distanceToMousePointer());
      myStage.wait(100);
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteDistanceToMousePointer();
  }
}
 

View on GitHub

Syntax

Java

.distanceToMousePointer()

Scratch

distance to [mouse-pointer v]?

Return

float

distanceToMousePointer()