Scratch for Java

Sprite::addCostume()

Add a costume to the sprite. The costume can either be an image or a part of a spritesheet.

Examples

import org.openpatch.scratch.*;

public class SpriteAddCostume {
  public SpriteAddCostume() {
    Stage myStage = new Stage(600, 240);
    Sprite zeta = new Sprite("green", "assets/zeta_green_badge.png");
    zeta.addCostume("yellow", "assets/zeta_yellow_badge.png");
    myStage.add(zeta);
    myStage.wait(1000);

    myStage.exit();
  }

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

View on GitHub

Syntax

Java

.addCostume(name, filePath)
.addCostume(name, filePath, x, y, width, height)

Scratch

Parameters

NameData TypeDescription
nameStringName of the costume
filePathStringPath to an image file.
xintx-Coordinate in a Spritesheet.
yinty-Coordinate in a Spritesheet.
widthintWidth of the image at the x- and y-coordinate in the Spritesheet.
heightintHeight of the image at the x- and y-coordinate in the Spritesheet.

Return

void