Rhythm
Game Engines Final Project
Loading...
Searching...
No Matches
components::texture::ComponentTexture Class Reference

A component that handles texture rendering for a GameObject. More...

Inheritance diagram for components::texture::ComponentTexture:

Public Member Functions

 this (GameObject *owner)
 Constructor for ComponentTexture.
 
 ~this ()
 Destructor for ComponentTexture.
 
override void Render (SDL_Renderer *renderer)
 Renders the texture using the given renderer.
 
override void Update ()
 Updates the animation frame if the texture is animated.
 
SDL_Rect * GetRectangle ()
 Gets the rectangle defining the texture's position and size.
 
 typeof (this) SetRectangle(SDL_Rect rectangle)
 Sets the rectangle defining the texture's position and size.
 
 typeof (this) SetImage(string path
 Sets the image for the texture from a file.
 
 typeof (this) SetRotation(double rotation)
 Sets the rotation angle for the texture.
 
double GetRotation ()
 Gets the rotation angle of the texture.
 
void SetPosition (int x, int y)
 Sets the position of the texture.
 
 typeof (this) LoadAnimations(string filename)
 Loads animations from a JSON file.
 
 typeof (this) LoadPlayerAnimations(string filename)
 Loads player animations from a JSON file.
 
 typeof (this) LoadBlockAnimation(string filename
 Loads block animation from a JSON file.
 
 assert (json.type==JSONType.OBJECT)
 
 assert (sprites.type==JSONType.OBJECT)
 
 if ("tileWidth" in sprites.object)
 
 if ("tileHeight" in sprites.object)
 
 for (int y=0;y< numFramesY;y++)
 
 assert (animations.type==JSONType.OBJECT)
 
 foreach (string key, JSONValue frameInfo;animations.object)
 
 typeof (this) PlayAnimation(string name)
 Plays the specified animation.
 
 typeof (this) SetFrameDuration(long duration)
 Sets the duration of each frame in the animation.
 

Public Attributes

SDL_Renderer * renderer
 
int index
 
JSONValue json = parseJSON(fileContent)
 
JSONValue sprites = json.object["sprites"][index]
 
int width = sprites.object["width"].integer.to!int
 
int height = sprites.object["height"].integer.to!int
 
int tileWidth = width
 
int tileHeight = height
 
int numFramesX = width / tileWidth
 
int numFramesY = height / tileHeight
 
JSONValue animations = json.object["sprites"][index]["animations"]
 
 mIsAnimated = true
 

Detailed Description

A component that handles texture rendering for a GameObject.

Constructor & Destructor Documentation

◆ this()

components::texture::ComponentTexture::this ( GameObject * owner)
inline

Constructor for ComponentTexture.

Parameters
ownerPointer to the GameObject that owns this component.

Member Function Documentation

◆ GetRectangle()

SDL_Rect * components::texture::ComponentTexture::GetRectangle ( )
inline

Gets the rectangle defining the texture's position and size.

Returns
Pointer to the SDL_Rect defining the texture's position and size.

◆ GetRotation()

double components::texture::ComponentTexture::GetRotation ( )
inline

Gets the rotation angle of the texture.

Returns
The rotation angle in degrees.

◆ Render()

override void components::texture::ComponentTexture::Render ( SDL_Renderer * renderer)
inline

Renders the texture using the given renderer.

Parameters
rendererThe SDL_Renderer to use for rendering.

◆ SetPosition()

void components::texture::ComponentTexture::SetPosition ( int x,
int y )
inline

Sets the position of the texture.

Parameters
xThe x-coordinate of the position.
yThe y-coordinate of the position.

◆ typeof() [1/8]

components::texture::ComponentTexture::typeof ( this )
inline

Loads animations from a JSON file.

Parameters
filenameThe path to the JSON file.
Returns
A reference to this ComponentTexture.

◆ typeof() [2/8]

components::texture::ComponentTexture::typeof ( this )

Loads block animation from a JSON file.

Parameters
filenameThe path to the JSON file.
indexThe index of the block animation in the JSON file.
Returns
A reference to this ComponentTexture.

◆ typeof() [3/8]

components::texture::ComponentTexture::typeof ( this )
inline

Loads player animations from a JSON file.

Parameters
filenameThe path to the JSON file.
Returns
A reference to this ComponentTexture.

◆ typeof() [4/8]

components::texture::ComponentTexture::typeof ( this )
inline

Plays the specified animation.

Parameters
nameThe name of the animation to play.
Returns
A reference to this ComponentTexture.

◆ typeof() [5/8]

components::texture::ComponentTexture::typeof ( this )
inline

Sets the duration of each frame in the animation.

Parameters
durationThe duration of each frame in frames.
Returns
A reference to this ComponentTexture.

◆ typeof() [6/8]

components::texture::ComponentTexture::typeof ( this )

Sets the image for the texture from a file.

Parameters
pathThe path to the image file.
rendererThe SDL_Renderer to use for rendering.
Returns
A reference to this ComponentTexture.

◆ typeof() [7/8]

components::texture::ComponentTexture::typeof ( this )
inline

Sets the rectangle defining the texture's position and size.

Parameters
rectangleThe new rectangle to set.
Returns
A reference to this ComponentTexture.

◆ typeof() [8/8]

components::texture::ComponentTexture::typeof ( this )
inline

Sets the rotation angle for the texture.

Parameters
rotationThe rotation angle in degrees.
Returns
A reference to this ComponentTexture.

Member Data Documentation

◆ index

int components::texture::ComponentTexture::index
Initial value:
{
string fileContent = readText(filename)

◆ renderer

SDL_Renderer* components::texture::ComponentTexture::renderer
Initial value:
{
mTexture = ResouceManager.GetInstance(renderer).LoadImageResource(path).mTexture

The documentation for this class was generated from the following file: