Scratch for Java

UISprite()

A sprite for buttons, bars and other parts of a user interface.

It differs from a normal sprite in two ways. It is drawn on top of everything else and stays put when the camera moves, and it can be given a width and a height in pixels instead of only a size in percent. Together with nine-slice scaling that lets one costume stretch to any size without the corners smearing:

public class Button extends UISprite {
  public Button() {
    this.addCostume("button", "ui/button.png");
    this.setNineSlice(12, 24, 12, 24);
    this.setWidth(600);
    this.setHeight(80);
  }
}

Examples

View on GitHub

Syntax

Java

new UISprite()
UISprite()

Create Shareable URL

Select Sections