Class WSprite

java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WSprite
Direct Known Subclasses:
WTiledSprite

public class WSprite extends WWidget
  • Field Details

    • currentFrame

      protected int currentFrame
    • currentFrameTime

      protected long currentFrameTime
    • frames

      protected Texture[] frames
    • frameTime

      protected int frameTime
    • lastFrame

      protected long lastFrame
    • singleImage

      protected boolean singleImage
    • tint

      protected int tint
  • Constructor Details

    • WSprite

      public WSprite(Texture texture)
      Create a new sprite with a single image.
      Parameters:
      texture - The image texture to display.
      Since:
      3.0.0
    • WSprite

      public WSprite(Identifier image)
      Create a new sprite with a single image.
      Parameters:
      image - The location of the image to display.
    • WSprite

      public WSprite(Identifier image, float u1, float v1, float u2, float v2)
      Create a new sprite with a single image and custom UV values.
      Parameters:
      image - The location of the image to display.
      u1 - the left edge of the texture
      v1 - the top edge of the texture
      u2 - the right edge of the texture
      v2 - the bottom edge of the texture
    • WSprite

      public WSprite(int frameTime, Identifier... frames)
      Create a new animated sprite.
      Parameters:
      frameTime - How long in milliseconds to display for. (1 tick = 50 ms)
      frames - The locations of the frames of the animation.
    • WSprite

      public WSprite(int frameTime, Texture... frames)
      Create a new animated sprite.
      Parameters:
      frameTime - How long in milliseconds to display for. (1 tick = 50 ms)
      frames - The locations of the frames of the animation.
      Since:
      3.0.0
  • Method Details

    • setImage

      public WSprite setImage(Identifier image)
      Sets the image of this sprite.
      Parameters:
      image - the new image
      Returns:
      this sprite
    • setFrames

      public WSprite setFrames(Identifier... frames)
      Sets the animation frames of this sprite.
      Parameters:
      frames - the frames
      Returns:
      this sprite
    • setImage

      public WSprite setImage(Texture image)
      Sets the image of this sprite.
      Parameters:
      image - the new image
      Returns:
      this sprite
      Since:
      3.0.0
    • setFrames

      public WSprite setFrames(Texture... frames)
      Sets the animation frames of this sprite.
      Parameters:
      frames - the frames
      Returns:
      this sprite
      Since:
      3.0.0
    • setTint

      public WSprite setTint(int tint)
      Sets the tint for this sprite to the following color-with-alpha. If you don't want to specify alpha, use setOpaqueTint(int) instead.
      Parameters:
      tint - the new tint
      Returns:
      this sprite
    • setOpaqueTint

      public WSprite setOpaqueTint(int tint)
      Sets the tint for this sprite to the following opaque color.
      Parameters:
      tint - the new tint
      Returns:
      this sprite
    • setUv

      public WSprite setUv(float u1, float v1, float u2, float v2)
      Sets the UV values of this sprite.
      Parameters:
      u1 - the left edge of the texture
      v1 - the top edge of the texture
      u2 - the right edge of the texture
      v2 - the bottom edge of the texture
      Returns:
      this sprite
      Since:
      1.8.0
    • canResize

      public boolean canResize()
      Description copied from class: WWidget
      Checks whether this widget can be resized using WWidget.setSize(int, int).
      Overrides:
      canResize in class WWidget
      Returns:
      true if this widget can be resized, false otherwise
    • paint

      @Environment(CLIENT) public void paint(DrawContext context, int x, int y, int mouseX, int mouseY)
      Description copied from class: WWidget
      Paints this widget.
      Overrides:
      paint in class WWidget
      Parameters:
      context - the draw context
      x - this widget's X coordinate on the screen
      y - this widget's Y coordinate on the screen
      mouseX - the X coordinate of the cursor
      mouseY - the X coordinate of the cursor
    • paintFrame

      @Environment(CLIENT) protected void paintFrame(DrawContext context, int x, int y, Texture texture)
      Paints a single frame for this sprite.
      Parameters:
      context - the draw context
      x - the X coordinate to draw it at
      y - the Y coordinate to draw it at
      texture - the texture to draw