Package ecs
Class SpriteRenderer
java.lang.Object
ecs.Component
ecs.SpriteRenderer
- All Implemented Interfaces:
Comparable<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
ConstructorDescriptionSpriteRenderer
(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 TypeMethodDescriptiongetColor()
org.joml.Vector4f
org.joml.Vector2f
getSize()
org.joml.Vector2f[]
boolean
isDirty()
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 dirtyvoid
setAlpha
(float a) Change the alpha/opacity of the sprite and/or colorvoid
setClean()
Used by the renderer to reset the state of the SpriteRenderer to clean.void
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 Vector4fvoid
setSize
(org.joml.Vector2f size) void
Change the sprite contained in the SpriteRenderer Component.void
setTexture
(Texture texture) Set the texture of the Sprite if required.void
start()
Initialize the Component, called once after creation by the parent GameObject.void
update
(float dt) Update method called every frame by parent GameObject
-
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
Create the spriteRenderer using a Color object, no sprite.- Parameters:
color
- of type Color, range from 0-255
-
SpriteRenderer
Create a spriteRenderer using a sprite that is already loaded. Default tint color is white (no tinting visible).- Parameters:
sprite
-
-
SpriteRenderer
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. -
update
public void update(float dt) Update method called every frame by parent GameObject -
getTexture
- Returns:
- type Texture of the sprite if applicable.
-
getSize
public org.joml.Vector2f getSize() -
setSize
public void setSize(org.joml.Vector2f size) -
setTexture
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
- 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
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
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.
-