Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprites flickering on the screen, when ClearBackground() IS used #11

Open
GabrieleC07 opened this issue Jun 19, 2024 · 2 comments
Open

Comments

@GabrieleC07
Copy link

GabrieleC07 commented Jun 19, 2024

I encountered an issue where if you use ClearBackground() and try to draw a sprite some sprites, they will flicker on the screen.
This is the code

unsafe {
        raylib_ffi::InitWindow(width_height.0,
            width_height.1,
            rl_str!(title)
        );
        while !raylib_ffi::WindowShouldClose() {
            raylib_ffi::draw!({
                raylib_ffi::ClearBackground(raylib_ffi::colors::GREEN);
                context.food.clone().draw();
                context.snake.clone().draw();
            });
        };
        raylib_ffi::CloseWindow();
}

Where food.draw() is this

unsafe {
             raylib_ffi::draw!(
                raylib_ffi::DrawRectangle(
                    self.pos.0 as i32,
                    self.pos.1 as i32,
                    GRID_CELL_SIZE.0 as i32,
                    GRID_CELL_SIZE.1 as i32,
                    raylib_ffi::colors::BLUE)
            );
}

and snake.draw() is this

unsafe {
            raylib_ffi::draw!(
                raylib_ffi::DrawRectangle(
                    self.body[0].pos.0,
                    self.body[0].pos.1,
                    GRID_CELL_SIZE.0 as i32,
                    GRID_CELL_SIZE.1 as i32,
                    raylib_ffi::colors::DARKGREEN)
            );
}

While looking at similiar issues it seems this happens if we DONT use ClearBackground so I just cant understand why

if I comment the ClearBackground everything works.

DISCLAIMER: I am a complete newbie on Raylib, this could very well not be the wrapper's fault, but having found the exact opposite results in the C Raylib version it seems weird

@ewpratten
Copy link
Owner

Probably not the wrappers fault. I think you are seeing flickering because you haven't set a target framerate (or enabled V-sync)

Try calling SetTargetFPS(60); after the window has been initialized

@GabrieleC07
Copy link
Author

GabrieleC07 commented Jun 19, 2024

Tried setting it in

unsafe {
 raylib_ffi::InitWindow(width_height.0, width_height.1, rl_str!(title) ); 
SetTargetFps(60);
while !raylib_ffi::WindowShouldClose() { 
     raylib_ffi::draw!({   raylib_ffi::ClearBackground(raylib_ffi::colors::GREEN); 
context.food.clone().draw(); context.snake.clone().draw(); 
}); 
}; 
raylib_ffi::CloseWindow(); 
}

But it still flickers

(This isnt the actual code and might be formatted differently)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants