Package org.openpatch.scratch
Class UISprite
java.lang.Object
org.openpatch.scratch.Sprite
org.openpatch.scratch.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);
}
}
-
Field Summary
Fields inherited from class org.openpatch.scratch.Sprite
DIRECTION_DOWN, DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_UP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeHeight(double amount) Changes the height of the sprite by the given number of pixels.voidchangeWidth(double amount) Changes the width of the sprite by the given number of pixels.voidLets the whole costume stretch again.voidsetHeight(double height) Sets the height of the sprite in pixels.voidsetNineSlice(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.voidsetWidth(double width) Sets the width of the sprite in pixels.Methods inherited from class org.openpatch.scratch.Sprite
addCostume, addCostume, addCostume, addCostumes, addedToStage, addSound, addSound, ask, broadcast, changePosition, changePosition, changeSize, changeTint, changeTransparency, changeVolume, changeX, changeY, clone, debug, disableHitbox, distanceToMousePointer, distanceToSprite, draw, drawDebug, enableHitbox, getAnswer, getCurrentCostumeIndex, getCurrentCostumeName, getDeltaTime, getDirection, getHeight, getHitbox, getMouse, getMouseX, getMouseY, getPen, getPosition, getShaders, getSize, getStage, getText, getTimer, getTimer, getTint, getTouchingSprite, getTouchingSprites, getTransparency, getVolume, getWidth, getX, getY, glide, goLayersBackwards, goLayersForwards, goToBackLayer, goToFrontLayer, goToMousePointer, goToRandomPosition, goToSprite, hide, ifOnEdgeBounce, isAsking, isGliding, isKeyPressed, isMouseDown, isSoundPlaying, isTouchingEdge, isTouchingMousePointer, isTouchingSprite, isTouchingSprite, isUI, isVisible, move, move, nextCostume, pickRandom, playSound, pointInDirection, pointInDirection, pointTowardsMousePointer, pointTowardsSprite, previousCostume, remove, removedFromStage, run, say, say, setDirection, setDirection, setHitbox, setHitbox, setPosition, setPosition, setRotationStyle, setSize, setTint, setTint, setTint, setTransparency, setUI, setVolume, setX, setY, show, stamp, stamp, stopAllSounds, stopSound, switchCostume, switchCostume, think, think, turnLeft, turnRight, whenAddedToStage, whenBackdropSwitches, whenClicked, whenIReceive, whenKeyPressed, whenKeyReleased, whenMouseClicked, whenMouseMoved, whenRemovedFromStage
-
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. -
setHeight
public void setHeight(double height) Sets the height of the sprite 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:
setNineSlicein classSprite- Parameters:
top- how many pixels of the costume belong to the top edgeright- how many pixels of the costume belong to the right edgebottom- how many pixels of the costume belong to the bottom edgeleft- how many pixels of the costume belong to the left edge
-
disableNineSlice
public void disableNineSlice()Lets the whole costume stretch again.- Overrides:
disableNineSlicein classSprite
-