Scratch for Java

Sprite::playSound()

Plays a sound.

Examples

import org.openpatch.scratch.*;
 
public class SpritePlaySound {
 
  public SpritePlaySound() {
    Stage myStage = new Stage(600, 240);
    Sprite zeta = new Sprite("green", "assets/zeta_green_badge.png");
    zeta.addSound("bump", "assets/bump.wav");
    myStage.add(zeta);
 
    while (myStage.getTimer().forMillis(3000)) {
      zeta.playSound("bump");
      myStage.wait(500);
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpritePlaySound();
  }
}
 

View on GitHub

Syntax

Java

.playSound(name)

Scratch

play sound (name) until done

Parameters

Name Data Type Description
name String The name of the sound to play

Return

void

playSound()