Looks
Speech and thought bubbles, costumes, size, visibility, graphic effects and layers. Costume and backdrop numbers start at 1, like in Scratch.
void say(Object message)
Sprites only
Shows a speech bubble that stays until the sprite says something else. say("") removes the bubble. Numbers are shown like Scratch shows them (10.0 is shown as 10).
Example
public void whenFlagClicked() {
say("Hello!");
waitSeconds(2);
say(""); // remove the bubble
}
void say(Object message, double seconds)
Sprites only
Shows a speech bubble for some seconds, then removes it. The script waits meanwhile.
Example
public void whenFlagClicked() {
say("Hello!", 2);
say("Welcome to JavaScratch.", 2);
}
void think(Object message)
Sprites only
Shows a thought bubble (with little circles instead of a pointer).
Example
public void whenClicked() {
think("Hmm... what should I do?");
}
void think(Object message, double seconds)
Sprites only
Shows a thought bubble for some seconds.
Example
public void whenFlagClicked() {
think("Zzz...", 3);
say("I'm awake!", 1);
}
Makes the sprite visible.
Example
public void whenFlagClicked() {
hide();
waitSeconds(1);
show(); // appears after one second
}
Makes the sprite invisible. Hidden sprites can't be clicked and don't touch anything.
Example
public void whenClicked() {
playSound("pop");
hide(); // disappear when clicked
}
boolean isVisible()
Sprites only
Tells whether the sprite is currently shown.
Example
public void whenKeyPressed(String key) {
if (key.equals("h")) {
if (isVisible()) hide(); else show();
}
}
void switchCostumeTo(String name)
Sprites only
Switches to the costume with that name (see the Costumes tab).
Example
public void whenFlagClicked() {
switchCostumeTo("bean-a");
}
void switchCostumeTo(int number)
Sprites only
Switches to a costume by number. Numbers start at 1, like in Scratch, and wrap around.
Example
public void whenFlagClicked() {
switchCostumeTo(pickRandom(1, 2));
}
void nextCostume()
Sprites only
Switches to the next costume (back to the first after the last). Great for walking animations.
Example
public void whenFlagClicked() {
forever(() -> {
move(3);
nextCostume();
waitSeconds(0.15);
ifOnEdgeBounce();
});
}
String getCostumeName()
Sprites only
Reports the current costume's name.
Example
public void whenClicked() {
nextCostume();
say(getCostumeName(), 1);
}
void switchBackdropTo(String name)
Sprites & Stage
Switches the stage's backdrop by name. Triggers whenBackdropSwitchesTo on every sprite.
Example
public void whenFlagClicked() {
switchBackdropTo("blue sky");
}
void switchBackdropTo(int number)
Sprites & Stage
Switches the backdrop by number (starting at 1).
Example
public void whenFlagClicked() {
switchBackdropTo(1);
}
void nextBackdrop()
Sprites & Stage
Switches to the next backdrop.
Example
public void whenKeyPressed(String key) {
if (key.equals("n")) nextBackdrop();
}
String backdropName()
Sprites & Stage
Reports the backdrop name.
Example
public void whenFlagClicked() {
if (backdropName().equals("night")) {
say("It's dark!", 2);
}
}
int backdropNumber()
Sprites & Stage
Reports the backdrop number.
Example
public void whenClicked() {
say("Level " + backdropNumber(), 1);
}
void setEffect(String effect, double value)
Sprites & Stage
Sets a graphic effect. "color" shifts the colours around the rainbow (0–200 is a full turn), "brightness" goes from -100 (black) to 100 (white), "ghost" from 0 (solid) to 100 (invisible).
Example
public void whenFlagClicked() {
setEffect("ghost", 50); // half transparent
}
void changeEffect(String effect, double by)
Sprites & Stage
Changes a graphic effect by an amount.
Example
public void whenFlagClicked() {
repeat(20, () -> changeEffect("ghost", 5)); // fade out
hide();
clearGraphicEffects();
}
void clearGraphicEffects()
Sprites & Stage
Removes all graphic effects.
Example
public void whenFlagClicked() {
clearGraphicEffects();
show();
}
void changeSizeBy(double percent)
Sprites only
Grows (positive) or shrinks (negative) the sprite.
Example
public void whenClicked() {
repeat(10, () -> changeSizeBy(5));
repeat(10, () -> changeSizeBy(-5)); // "pulse"
}
void setSizeTo(double percent)
Sprites only
Sets the size in percent of the costume's normal size (100 = normal). Very small and very large sizes are limited, like in Scratch.
Example
public void whenFlagClicked() {
setSizeTo(50);
}
double getSize()
Sprites only
Reports the size.
Example
public void whenFlagClicked() {
repeatUntil(() -> getSize() >= 200, () -> changeSizeBy(2));
}
void goToFront()
Sprites only
Draws this sprite in front of all other sprites.
Example
public void whenClicked() {
goToFront();
}
void goToBack()
Sprites only
Draws this sprite behind all other sprites (but in front of the backdrop).
Example
public void whenFlagClicked() {
goToBack(); // e.g. scenery sprites
}
void goBackLayers(int n)
Sprites only
Moves the sprite back by some layers.
Example
public void whenClicked() {
goBackLayers(1);
}
void goForwardLayers(int n)
Sprites only
Moves the sprite forward by some layers.
Example
public void whenClicked() {
goForwardLayers(1);
}