Hello guys,
so let's assume we have a display refresh rate of 144hz and i want to display a sprite with 9 frames in 0.25 second.
Now if it was 1 second instead, it would take 16 frames to update the sprite's frame by one.
In this case, it would take only 4 frames before it updates the sprite's frame by one.
I also want it to also work for a display refresh rate of 60hz.
So in the case of 60hz, it would take 1.66666666667 frames instead to update it.
My sprite function looks like this :
Of course it is wrong...
See this line in particular
How can i fix this ?
Thanks
so let's assume we have a display refresh rate of 144hz and i want to display a sprite with 9 frames in 0.25 second.
Now if it was 1 second instead, it would take 16 frames to update the sprite's frame by one.
In this case, it would take only 4 frames before it updates the sprite's frame by one.
I also want it to also work for a display refresh rate of 60hz.
So in the case of 60hz, it would take 1.66666666667 frames instead to update it.
My sprite function looks like this :
Code Select
void Put_sprite_top_left(uint_fast32_t a, double top_left_x, double top_left_y, int w, int h, int frame_start, int frame_end, int loop, double seconds)
{
SDL_Rect position;
SDL_Rect frame;
position.x = (int) (current_internal_resolution_width * top_left_x);
position.y = (int) (current_internal_resolution_height * top_left_y);
position.w = w;
position.h = h;
if (!(sprites_current_frame_[a] >= (double)frame_end && loop == 0))
{
if (sprites_current_frame_[a] < frame_end)
{
sprites_current_frame_[a] += ((seconds)*(double)(frame_end-frame_start)) * (1.0/Get_Refresh_rate) ;
}
if ((sprites_current_frame_[a] >= (double)frame_end && loop == 1) || (sprites_current_frame_[a] < 0.0 && sprites_current_frame_[a] == 0.0))
{
sprites_current_frame_[a] = (double)frame_start;
}
}
printf("sprites_current_frame_[a] %f\n", sprites_current_frame_[a]);
frame.x = (int)(sprites_current_frame_[a])*(w);
frame.y = 0;
frame.w = w;
frame.h = h;
SDL_RenderCopy(renderer, texture_library_memory[a], &frame, &position);
}
Of course it is wrong...
See this line in particular
Code Select
sprites_current_frame_[a] += ((seconds)*(double)(frame_end-frame_start)) * (1.0/Get_Refresh_rate) ;
How can i fix this ?
Thanks