Scratch for Java

Sprite::switchCostume()

Changes the sprite's costume to the specified one.

Examples

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

public class SpriteSwitchCostume {
  public SpriteSwitchCostume() {
    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(3000);
    zeta.switchCostume("yellow");
    myStage.wait(3000);
    myStage.exit();
  }

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

View on GitHub

Syntax

Java

.switchCostume(name)
.switchCostume(index)

Scratch

Parameters

NameData TypeDescription
nameStringName of the costume.
indexintIndex of the costume.

Return

void