Scratch for Java

Sprite::isTouchingSprite()

Returns true if the sprite is touched by the other sprite.

Examples

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

public class SpriteIsTouchingSprite {
  public SpriteIsTouchingSprite() {
    Stage myStage = new Stage(600, 240);

    Sprite gamma = new Sprite("gamma", "assets/gamma_purple_badge.png");
    gamma.setPosition(-120, 50);
    myStage.add(gamma);
    Sprite zeta = new Sprite("zeta", "assets/zeta_green_badge.png");
    zeta.setPosition(120, 50);
    myStage.add(zeta);

    while (!gamma.isTouchingSprite(zeta)) {
      gamma.changeX(5);
      zeta.changeX(-5);
      myStage.wait(100);
    }
    myStage.exit();
  }

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

View on GitHub

Syntax

Java

.isTouchingMousePointer(sprite)

Scratch

Parameters

NameData TypeDescription
spriteSpriteA reference to a sprite.

Return

boolean