Package ecs

Class SpriteRenderer

java.lang.Object
ecs.Component
ecs.SpriteRenderer
All Implemented Interfaces:
Comparable<Component>

public class SpriteRenderer extends Component
SpriteRenderer is a component that can be added to a GameObject. it can contain a solid color, a semi-transparent color, or a texture. Sprites can be tinted by the color value.
Author:
Asher Haun, Gabe
  • Nested Class Summary

    Nested classes/interfaces inherited from class ecs.Component

    Component.ComponentOrder
  • Field Summary

    Fields inherited from class ecs.Component

    gameObject
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpriteRenderer(Color color, org.joml.Vector2f size)
    Create the spriteRenderer using a Color object, no sprite.
    SpriteRenderer(Sprite sprite, org.joml.Vector2f size)
    Create a spriteRenderer using a sprite that is already loaded.
    SpriteRenderer(String path, org.joml.Vector2f size)
    Create a spriteRenderer using an image from the fileSystem.
    SpriteRenderer(org.joml.Vector4f color, org.joml.Vector2f size)
    Create the spriteRenderer using a color vector, no sprite.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    org.joml.Vector4f
     
    org.joml.Vector2f
     
    org.joml.Vector2f[]
     
     
    boolean
    Used by the renderer to determine if this sprite should be sent back to the GPU to be redrawn.
    void
    Mark this Sprite renderer as dirty
    void
    setAlpha(float a)
    Change the alpha/opacity of the sprite and/or color
    void
    Used by the renderer to reset the state of the SpriteRenderer to clean.
    void
    setColor(Color color)
    Change the color by passing a Color object, converting it to a normalized Vector4f.
    void
    setColor(org.joml.Vector4f color)
    Change the color by passing a Vector4f
    void
    setSize(org.joml.Vector2f size)
     
    void
    setSprite(Sprite sprite)
    Change the sprite contained in the SpriteRenderer Component.
    void
    Set the texture of the Sprite if required.
    void
    Initialize the Component, called once after creation by the parent GameObject.
    void
    update(float dt)
    Update method called every frame by parent GameObject

    Methods inherited from class ecs.Component

    compareTo, debug, position, remove, setPosition

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SpriteRenderer

      public SpriteRenderer(org.joml.Vector4f color, org.joml.Vector2f size)
      Create the spriteRenderer using a color vector, no sprite.
      Parameters:
      color - of type JOML Vector4f, range from 0-1
    • SpriteRenderer

      public SpriteRenderer(Color color, org.joml.Vector2f size)
      Create the spriteRenderer using a Color object, no sprite.
      Parameters:
      color - of type Color, range from 0-255
    • SpriteRenderer

      public SpriteRenderer(Sprite sprite, org.joml.Vector2f size)
      Create a spriteRenderer using a sprite that is already loaded. Default tint color is white (no tinting visible).
      Parameters:
      sprite -
    • SpriteRenderer

      public SpriteRenderer(String path, org.joml.Vector2f size)
      Create a spriteRenderer using an image from the fileSystem.
      Parameters:
      path - to the image (ie. "src/assets/images/pepper.png")
  • Method Details

    • start

      public void start()
      Initialize the Component, called once after creation by the parent GameObject.
      Overrides:
      start in class Component
    • update

      public void update(float dt)
      Update method called every frame by parent GameObject
      Overrides:
      update in class Component
      Parameters:
      dt - Engine.deltaTime
    • getTexture

      public Texture getTexture()
      Returns:
      type Texture of the sprite if applicable.
    • getSize

      public org.joml.Vector2f getSize()
    • setSize

      public void setSize(org.joml.Vector2f size)
    • setTexture

      public void setTexture(Texture texture)
      Set the texture of the Sprite if required.
      Parameters:
      texture - the new texture of this sprite
    • getTexCoords

      public org.joml.Vector2f[] getTexCoords()
      Returns:
      Vector2f array of the UV coordinates of the sprite if applicable.
    • getColorVector

      public org.joml.Vector4f getColorVector()
      Returns:
      a Vector4f containing the normalized (0-1) color values (R, G, B, and A)
    • getColor

      public Color getColor()
      Returns:
      type Color in standard RGBA form in the range 0-255
    • setColor

      public void setColor(org.joml.Vector4f color)
      Change the color by passing a Vector4f
      Parameters:
      color - vector, values should be in the range of 0-1
    • setColor

      public void setColor(Color color)
      Change the color by passing a Color object, converting it to a normalized Vector4f.
      Parameters:
      color - should be in range of 0-255
    • setAlpha

      public void setAlpha(float a)
      Change the alpha/opacity of the sprite and/or color
      Parameters:
      a - alpha/opacity
    • setSprite

      public void setSprite(Sprite sprite)
      Change the sprite contained in the SpriteRenderer Component.
      Parameters:
      sprite -
    • isDirty

      public boolean isDirty()
      Used by the renderer to determine if this sprite should be sent back to the GPU to be redrawn.
      Returns:
      true or false if the sprite or color has changes since last draw.
    • markDirty

      public void markDirty()
      Mark this Sprite renderer as dirty
    • setClean

      public void setClean()
      Used by the renderer to reset the state of the SpriteRenderer to clean.