Class UISprite

java.lang.Object
org.openpatch.scratch.Sprite
org.openpatch.scratch.UISprite

public class UISprite extends Sprite
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);
   }
 }
 
  • Constructor Details

    • UISprite

      public UISprite()
      Creates a sprite that is drawn as part of the user interface.
  • Method Details

    • setWidth

      public void setWidth(double width)
      Sets the width of the sprite in pixels.
      Overrides:
      setWidth in class Sprite
      Parameters:
      width - the width in pixels
    • setHeight

      public void setHeight(double height)
      Sets the height of the sprite in pixels.
      Overrides:
      setHeight in class Sprite
      Parameters:
      height - the height in pixels
    • changeWidth

      public void changeWidth(double amount)
      Changes the width of the sprite by the given number of pixels.
      Parameters:
      amount - how many pixels to add to the width
    • changeHeight

      public void changeHeight(double amount)
      Changes the height of the sprite by the given number of pixels.
      Parameters:
      amount - how many pixels to add to the height
    • setNineSlice

      public void setNineSlice(int top, int right, int bottom, int left)
      Keeps the corners and edges of the costume from stretching when the sprite is resized, so that a button costume can be made any size.
      Overrides:
      setNineSlice in class Sprite
      Parameters:
      top - how many pixels of the costume belong to the top edge
      right - how many pixels of the costume belong to the right edge
      bottom - how many pixels of the costume belong to the bottom edge
      left - how many pixels of the costume belong to the left edge
    • disableNineSlice

      public void disableNineSlice()
      Lets the whole costume stretch again.
      Overrides:
      disableNineSlice in class Sprite