20 std::string texture_name =
"";
21 TazColor default_color = { 255, 255, 255, 255 };
22 TazColor color = { 255, 255, 255, 255 };
25 SDL_FRect srcRect = { 0,0,0,0 };
30 SDL_RendererFlip spriteFlip = SDL_FLIP_NONE;
50 void setTex(std::string
id)
53 gl_texture = TextureManager::getInstance().Get_GLTexture(
id);
54 srcRect.w = (float)gl_texture->width;
55 srcRect.h = (float)gl_texture->height;
66 srcRect.x = srcRect.y = 0;
67 srcRect.w = transform->size.x;
68 srcRect.h = transform->size.y;
72 void update(
float deltaTime)
override
78 if (gl_texture == NULL)
83 float screenScale = window.getScale();
86 transform->getPosition().x * screenScale,
87 transform->getPosition().y * screenScale,
88 transform->getPosition().z);
91 transform->size.x * transform->scale * screenScale,
92 transform->size.y * transform->scale * screenScale);
94 float srcUVposX = spriteFlip == SDL_FLIP_HORIZONTAL ?
95 (srcRect.x + srcRect.w) / gl_texture->width :
96 srcRect.x / gl_texture->width;
97 float srcUVposY = (srcRect.y) / gl_texture->height;
99 float srcUVw = spriteFlip == SDL_FLIP_HORIZONTAL ?
100 -srcRect.w / gl_texture->width :
101 srcRect.w / gl_texture->width;
102 float srcUVh = srcRect.h / gl_texture->height;
104 glm::vec4 uv(srcUVposX, srcUVposY, srcUVw, srcUVh);
106 batch.draw(v_index, size, transform->getPosition(), transform->rotation, uv, gl_texture->id);
108 glDisableVertexAttribArray(0);
109 glDisableVertexAttribArray(1);
110 glDisableVertexAttribArray(2);
112 glBindBuffer(GL_ARRAY_BUFFER, 0);
117 void SetAnimation(
int idX,
int idY,
size_t fr,
float sp,
const Animation::animType type,
int reps = 0)
119 animation =
Animation(idX, idY, fr, sp, type, reps);
122 void SetFlashAnimation(
size_t fr,
float sp,
const Animation::animType type,
const std::vector<float>& flashTimes,
TazColor flashC,
int reps = 0)
124 flash_animation =
FlashAnimation(fr, sp, type, flashTimes, flashC, reps);
127 void setCurrFrame() {
128 this->srcRect.x = (this->animation.indexX * this->transform->size.x) + (this->srcRect.w * animation.cur_frame_index);
129 this->srcRect.y = this->animation.indexY * this->transform->size.y;
132 void setFlashFrame() {
133 this->color = this->flash_animation.flashColor * this->flash_animation.interpolation_a
134 + default_color * (1 - this->flash_animation.interpolation_a);
140 gl_texture =
nullptr;
147 std::string GetComponentName()
override {
148 return "SpriteComponent";
151 void showGUI(std::vector<BaseComponent*> otherComponents = {})
override {
152 showGUI(otherComponents, { entity });
155 void showGUI(std::vector<BaseComponent*> otherComponents, std::vector<Entity*> otherEntities)
override {
159 std::vector<std::string> textureNames = TextureManager::getInstance().Get_GLTextureNames();
161 if (!textureNames.empty()) {
162 std::vector<const char*> items;
163 for (
const std::string& name : textureNames)
164 items.push_back(name.c_str());
166 if (ImGui::Combo(
"Textures", ¤tItem, items.data(), (
int)items.size())) {
167 if (!textureNames[currentItem].empty()) {
168 setTex(textureNames[currentItem]);