Scratch for Java

Stage::setCursor()

Sets the cursor. It is recommended that the size is 16x16 or 32x32 pixels. The active spot of the cursor defaults to the top left corner (x = 0, y = 0). You can set the active spot by using the x and y argument. The values for the parameters x and y must be less than the dimensions of the image.

Examples

import org.openpatch.scratch.*;

public class StageSetCursor {

  public StageSetCursor() {
    Stage myStage = new Stage(600, 240);
    while (myStage.getTimer().forMillis(5000)) {
      if (myStage.getMouseX() < 0) {
        myStage.setCursor("assets/cursor_hand.png");
      } else {
        myStage.setCursor("assets/cursor_sword.png", 30, 30);
      }
      myStage.display("Mouse: " + myStage.getMouseX() + ", " + myStage.getMouseY());
      myStage.wait(16);
    }
    myStage.exit();
  }

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

View on GitHub

Syntax

Java

.setCursor(path), .setCursor(path,x,y)

Scratch

Parameters

NameData TypeDescription
pathStringThe path to the image
xintThe x coordinate of the active spot of the cursor.
yintThe y coordinate of the active spot of the cursor.

Return

void