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

switch costume to [ v]

Parameters

Name Data Type Description
name String Name of the costume.
index int Index of the costume.

Return

void

switchCostume()