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();
}
}
Syntax
Java
void whenMouseMoved(x, y)
Scratch
when mouse moved :: hat
Parameters
Name | Data Type | Description |
---|---|---|
x | float | The x coordinate of the mouse cursor |
y | float | The y coordinate of the mouse cursor |
Return
void