Scratch for Java

Stage::whenBackdropSwitches()

This method is called when the backdrop of the stage switches. The method will receive the name of the new backdrop as a paramter.

Examples

import org.openpatch.scratch.*;

public class StageWhenBackdropSwitches {

  public StageWhenBackdropSwitches() {
    Stage myStage = new CustomStage();
    myStage.wait(1000);
    myStage.nextBackdrop();
    myStage.wait(1000);
    myStage.nextBackdrop();
    myStage.wait(1000);
    Window.getInstance().exit();
  }

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

class CustomStage extends Stage {

  public CustomStage() {
    super(254, 100);
    this.addBackdrop("forest", "assets/background_forest.png");
    this.addBackdrop("sea", "assets/background_sea.png");
  }

  public void whenBackdropSwitches(String name) {
    if (name.equals("sea")) {
      this.display("Sea");
    } else if (name.equals("forest")) {
      this.display("Team Trees!");
    }
  }
}

View on GitHub

Syntax

Java

void whenBackdropSwitches(name)

Scratch

Parameters

NameData TypeDescription
nameStringName of the new backdrop

Return

void