NWengine 0.9
Loading...
Searching...
No Matches
Sprite.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "GameObject.h"
9#include "Shader.h"
10#include "Texture.h"
11#include "image.h"
12#include "Primitives.h"
13
22
26class Sprite : public GameComponent {
27private:
28public:
29 static std::string GetType() { return "Sprite"; };
30 TextureIdentifier _texId{};
31 Texture* texture = nullptr;
32
34 int _lastSortingLayer = 0;
35 bool _shouldDraw = 1;
36 bool _isRendered = 1;
37
39 Shader* shader = nullptr;
41 GameObject* attachedObj = nullptr;
42 int sortingLayer = 0;
43 double zbuffer = 1.0;
48 Sprite() = default;
49
54 Sprite(GameObject* go);
55
59 ~Sprite();
60
66 void SetTexture(std::string path, bool alpha = 1);
67
73 void SetTexture(const Image* image, TextureIdentifierPtr texId);
74
79 void SetTexture(Texture* tex);
80
85 void SetShader(std::string path);
86
92 void SetShader(const ShaderText& st, ShaderIdentifier* id);
93
98 void SetShader(Shader* shader);
99
104 void SetSortingLayer(int order);
105
109 void Render();
110
114 void StopRendering();
115
121
125 void UnBatch();
126
130 void Update() override;
131
138 int Serialize(std::fstream* data, int offset) override;
139
146 int Deserialize(std::fstream* data, int offset) override;
147
152 void SetGameObject(void* go) override;
153
158 void* GetGameObject() override;
159
165 static int DefaultSpriteDrawCallback(void* data);
166};
Defines the GameObject class and its related components.
BatchType
Enumerates the batch types for sprites.
Definition Sprite.h:17
@ UNBATCHED
Definition Sprite.h:18
@ STATIC_BATCH
Definition Sprite.h:19
@ DYNAMIC_BATCH
Definition Sprite.h:20
Base class for game components.
Definition GameObject.h:29
Class representing a game object.
Definition GameObject.h:68
Represents an image asset.
Definition Image.h:12
The Quad class represents a quad shape.
Definition Primitives.h:56
Class representing a shader asset.
Definition Shader.h:22
Represents a game sprite.
Definition Sprite.h:26
Sprite()=default
Default constructor for the Sprite class.
double zbuffer
Definition Sprite.h:43
int sortingLayer
Definition Sprite.h:42
void StopRendering()
Stops rendering the sprite.
Definition Sprite.cpp:75
void * GetGameObject() override
Gets the GameObject that the sprite is attached to.
Definition Sprite.cpp:127
int Serialize(std::fstream *data, int offset) override
Serializes the sprite data.
Definition Sprite.cpp:85
void UnBatch()
Unbatches the sprite.
Definition Sprite.cpp:65
Quad container
Definition Sprite.h:40
void Render()
Renders the sprite.
Definition Sprite.cpp:70
void SetTexture(std::string path, bool alpha=1)
Sets the texture of the sprite from a file path.
Definition Sprite.cpp:14
~Sprite()
Destructor for the Sprite class.
Definition Sprite.cpp:131
int Deserialize(std::fstream *data, int offset) override
Deserializes the sprite data.
Definition Sprite.cpp:103
void Batch(BatchType type=BatchType::DYNAMIC_BATCH)
Batches the sprite.
Definition Sprite.cpp:59
void SetShader(std::string path)
Sets the shader of the sprite from a file path.
Definition Sprite.cpp:34
static int DefaultSpriteDrawCallback(void *data)
Default draw callback for sprites.
Definition Sprite.cpp:143
void Update() override
Updates the sprite.
Definition Sprite.cpp:79
void SetSortingLayer(int order)
Sets the sorting layer of the sprite.
Definition Sprite.cpp:48
void SetGameObject(void *go) override
Sets the GameObject that the sprite is attached to.
Definition Sprite.cpp:124
fVec3 vertexAttributes
Definition Sprite.h:38
Class representing a texture asset.
Definition Texture.h:81
Struct representing the text of a shader.
Definition Shader.h:12
Struct representing the identifier of a texture.
Definition Texture.h:12