Scratch for Java

Sprite::addSound()

Adds a new sound. The file needs to be a mp3, wav or ogg.

Examples

import org.openpatch.scratch.*;
 
public class SpriteAddSound {
 
  public SpriteAddSound() {
    var myStage = new Stage(600, 240);
    Sprite zeta = new Sprite("green", "assets/zeta_green_badge.png");
    zeta.addSound("bump", "assets/bump.wav");
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteAddSound();
  }
}
 

View on GitHub

Syntax

Java

.addSound(name, filePath)

Scratch

add sound (name) (file path)

Parameters

Name Data Type Description
name String The name of the sound
filePath String The file path of the sound file

Return

void

addSound()