20 bool _isMainMenu =
false;
23 std::string texture_name =
"";
24 Color default_color = { 255, 255, 255, 255 };
25 Color color = { 255, 255, 255, 255 };
28 SDL_FRect srcRect = {0,0,0,0};
34 SDL_RendererFlip spriteFlip = SDL_FLIP_NONE;
49 _isMainMenu = isMainMenu;
57 void setTex(std::string
id)
60 gl_texture = TextureManager::getInstance().Get_GLTexture(
id);
61 srcRect.w = (float)gl_texture->width;
62 srcRect.h = (float)gl_texture->height;
73 srcRect.x = srcRect.y = 0;
74 srcRect.w = transform->size.x;
75 srcRect.h = transform->size.y;
79 void update(
float deltaTime)
override
85 if (gl_texture == NULL)
90 float screenScale = window.getScale();
93 transform->getPosition().x * screenScale,
94 transform->getPosition().y * screenScale,
95 transform->getPosition().z);
98 transform->size.x * transform->scale * screenScale,
99 transform->size.y * transform->scale * screenScale);
101 float srcUVposX = spriteFlip == SDL_FLIP_HORIZONTAL ?
102 (srcRect.x + srcRect.w) / gl_texture->width :
103 srcRect.x / gl_texture->width;
104 float srcUVposY = (srcRect.y) / gl_texture->height;
106 float srcUVw = spriteFlip == SDL_FLIP_HORIZONTAL ?
107 -srcRect.w / gl_texture->width :
108 srcRect.w / gl_texture->width;
109 float srcUVh = srcRect.h / gl_texture->height;
111 glm::vec4 uv(srcUVposX, srcUVposY, srcUVw, srcUVh);
113 batch.draw(v_index, size, transform->bodyCenter, transform->rotation, uv, gl_texture->id);
115 glDisableVertexAttribArray(0);
116 glDisableVertexAttribArray(1);
117 glDisableVertexAttribArray(2);
119 glBindBuffer(GL_ARRAY_BUFFER, 0);
124 void SetAnimation(
int idX,
int idY,
size_t fr,
float sp,
const Animation::animType type,
int reps = 0)
126 animation =
Animation(idX, idY, fr, sp, type, reps);
129 void SetMovingAnimation(
int idX,
int idY,
size_t fr,
float sp,
const Animation::animType type,
const std::vector<glm::vec2>& _positions,
const std::vector<int>& _zIndices,
const std::vector<int>& _rotations,
int reps = 0)
131 moving_animation =
MovingAnimation(idX, idY, fr, sp, type, _positions, _zIndices, _rotations, reps);
134 void SetFlashAnimation(
int idX,
int idY,
size_t fr,
float sp,
const Animation::animType type,
const std::vector<float>& flashTimes,
Color flashC,
int reps = 0)
136 flash_animation =
FlashAnimation(idX, idY, fr, sp, type, flashTimes, flashC, reps);
139 void setCurrFrame() {
140 this->srcRect.x = (this->animation.indexX * this->transform->size.x) + ( this->srcRect.w * animation.cur_frame_index);
141 this->srcRect.y = this->animation.indexY * this->transform->size.y;
144 void setMoveFrame() {
146 this->transform->setPosition_X(((this->transform->getPosition().x) + this->moving_animation.indexX) + (this->moving_animation.positions[0].x * moving_animation.cur_frame_index));
147 this->transform->setPosition_Y(((this->transform->getPosition().y) + this->moving_animation.indexY) + (this->moving_animation.positions[0].y * moving_animation.cur_frame_index));
150 void setSpecificMoveFrame() {
152 this->transform->setPosition_X(((this->transform->getPosition().x) + this->moving_animation.indexX) + (this->moving_animation.positions[moving_animation.cur_frame_index].x));
153 this->transform->setPosition_Y(((this->transform->getPosition().y) + this->moving_animation.indexY) + (this->moving_animation.positions[moving_animation.cur_frame_index].y));
156 void setFlashFrame() {
157 this->color = this->flash_animation.flashColor * this->flash_animation.interpolation_a
158 + default_color * (1 - this->flash_animation.interpolation_a);
164 gl_texture =
nullptr;
171 std::string GetComponentName()
override {
172 return "SpriteComponent";
175 void showGUI()
override {
179 std::vector<std::string> textureNames = TextureManager::getInstance().Get_GLTextureNames();
181 static int currentItem = 0;
182 if (!textureNames.empty()) {
183 std::vector<const char*> items;
184 for (
const std::string& name : textureNames)
185 items.push_back(name.c_str());
187 if (ImGui::Combo(
"Textures", ¤tItem, items.data(), (
int)items.size())) {
188 if (!textureNames[currentItem].empty()) {
189 setTex(textureNames[currentItem]);