0
\$\begingroup\$

I'm quite new to Raylib and trying to make a simple snow particle system. I managed to make it as below code and built it. But when I run it, the snowflakes flicker and I can easily notice it.

Here's the snowflake image(png) link.

snow.png

and below is the captured video of flickering for your reference.

captured video

Can anyone please tell me what I'm missing here? Thank you.

#include "raylib.h" #include "raymath.h" const int screenWidth = 640; const int screenHeight = 480; Texture2D texture; typedef struct { Vector2 position; Vector2 velocity; } s_particle; const int number_particles = 400; s_particle particles[number_particles]; void spawn_particle(s_particle* pt) { pt->position.x = GetRandomValue(-screenWidth * 0.4f, screenWidth); pt->position.y = GetRandomValue(-screenHeight * 2, 0); float max = 10000.0f; pt->velocity.x = (float)(GetRandomValue(1, (int)max) / max) * 0.5f; pt->velocity.y = (float)(GetRandomValue(1, (int)max) / max) + 0.8f; } void draw_particle(s_particle pt[]) { for (int i = 0; i < number_particles; i++) { s_particle* particle = &pt[i]; particle->position.x += particle->velocity.x; particle->position.y += particle->velocity.y; if (particle->position.x > screenWidth || particle->position.y > screenHeight) spawn_particle(particle); DrawTexture(texture, particle->position.x, particle->position.y, WHITE); } } int main(void) { InitWindow(screenWidth, screenHeight, "raylib example"); SetTargetFPS(60); texture = LoadTexture("snow.png"); for (int i = 0; i < number_particles; i++) { spawn_particle(&particles[i]); } while (!WindowShouldClose()) { BeginDrawing(); { ClearBackground(BLACK); draw_particle(particles); DrawFPS(0, 0); } EndDrawing(); } UnloadTexture(texture); CloseWindow(); return 0; } 
\$\endgroup\$
2
  • \$\begingroup\$ Are you able to capture a gif or video of the flickering you're seeing? \$\endgroup\$ Commented May 9 at 17:01
  • \$\begingroup\$ @DMGregory Sure, Please check the link for the flickering problem. link \$\endgroup\$ Commented May 10 at 6:15

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.