From ac7ba6dc94f6eb2d8cf9092391714247bb947148 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Tue, 17 Dec 2024 11:11:59 +0300 Subject: Fix embarrassing bug - The position and size of the source rectangle for animations was dependent on the display scale, this is incredibly stupid and shouldn't have happened. --- Week1-Pacman/src/demo.c | 28 ++++------------------------ Week1-Pacman/src/main.c | 2 +- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/Week1-Pacman/src/demo.c b/Week1-Pacman/src/demo.c index 85ee2a3..2ff021e 100644 --- a/Week1-Pacman/src/demo.c +++ b/Week1-Pacman/src/demo.c @@ -19,18 +19,8 @@ void demo_rendercopy(struct demo* demo, const float scale_x = demo->display_scale_x; const float scale_y = demo->display_scale_y; - SDL_Rect new_srect; SDL_Rect new_drect; - if(s_rect) { - new_srect = (SDL_Rect){ - .x = s_rect->x * scale_x, - .y = s_rect->y * scale_y, - .w = s_rect->w * scale_x, - .h = s_rect->h * scale_y - }; - } - if(d_rect) { new_drect = (SDL_Rect){ .x = d_rect->x * scale_x, @@ -40,9 +30,9 @@ void demo_rendercopy(struct demo* demo, }; } - //Handle edge case where s_rect or d_rect are NULL + //Handle edge case where d_rect is NULL SDL_RenderCopy(demo->ren, texture, - s_rect ? &new_srect : NULL, + s_rect, d_rect ? &new_drect : NULL); } @@ -56,18 +46,8 @@ void demo_rendercopy_ex(struct demo* demo, const float scale_x = demo->display_scale_x; const float scale_y = demo->display_scale_y; - SDL_Rect new_srect; SDL_Rect new_drect; - if(s_rect) { - new_srect = (SDL_Rect){ - .x = s_rect->x * scale_x, - .y = s_rect->y * scale_y, - .w = s_rect->w * scale_x, - .h = s_rect->h * scale_y - }; - } - if(d_rect) { new_drect = (SDL_Rect){ .x = d_rect->x * scale_x, @@ -77,9 +57,9 @@ void demo_rendercopy_ex(struct demo* demo, }; } - //Handle edge case where s_rect or d_rect are NULL + //Handle edge case where d_rect is NULL SDL_RenderCopyEx(demo->ren, texture, - s_rect ? &new_srect : NULL, + s_rect, d_rect ? &new_drect : NULL, angle, center, diff --git a/Week1-Pacman/src/main.c b/Week1-Pacman/src/main.c index 895c359..e4113be 100644 --- a/Week1-Pacman/src/main.c +++ b/Week1-Pacman/src/main.c @@ -32,7 +32,7 @@ int main() { .initial_angle = 90.0 * i, .initial_frame_count = 3, - .initial_frame_times = (float[]){0.10, 0.10, 0.10}, + .initial_frame_times = (float[]){0.05, 0.05, 0.05}, .initial_frames = (SDL_Rect[]) { { .x = 0, -- cgit v1.2.3