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

Fancy console is not cleared if .cls() is the only operation #278

Closed
nicolaracco opened this issue Jul 31, 2022 · 6 comments · Fixed by #295
Closed

Fancy console is not cleared if .cls() is the only operation #278

nicolaracco opened this issue Jul 31, 2022 · 6 comments · Fixed by #295

Comments

@nicolaracco
Copy link

Following the Hands On Rust's first chapter, I implemented the "Flappy Dragon" game. After that I followed this post https://hands-on-rust.com/2021/02/08/from-flappy-dragon-to-flappy-bonus/ to improve it, obtaining this: https://gist.github.com/nicolaracco/18d6ed34571f8f4cf4a42b39457f38a1

But I noticed that when the player hits an obstacle, it is still rendered on screen, so I added a ctx.cls() call on the dead function: https://gist.github.com/nicolaracco/18d6ed34571f8f4cf4a42b39457f38a1#file-flappy_dragon-rs-L135

But even with this call, when the "You are dead" screen is shown, the dragon sprite stays on screen. If I add any other draw call (like another ctx.set_fancy call), the problem disappears (but I would not to draw anything in this case :))

@thebracket
Copy link
Collaborator

I think this is fixed in the current Github version; there is a "set dirty" call (indicating that it needs redrawing) in place. Would you mind switching your project to try the current build?

In Cargo.toml you can replace:

bracket-lib = "0.8"

with

bracket-lib = { git = "https://github.com/amethyst/bracket-lib.git" }

In the interim, I'll see if I can cook up a test case to be sure.

@patchfx
Copy link
Contributor

patchfx commented Aug 9, 2022

@thebracket The problem still exists in the current master branch. I patched this locally by changing the cls() function in FancyConsole .

    fn cls(&mut self) {
        self.is_dirty = true;
        for tile in &mut self.tiles {
            tile.glyph = 32;
            tile.fg = RGBA::from_u8(255, 255, 255, 255);
            tile.bg = RGBA::from_u8(0, 0, 0, 255);
        }
    }

This effectively replicates the behaviour of a simple console. I didn't open a PR as I was following the related thread #255

Hope this helps!

@nicolaracco
Copy link
Author

Sorry for the delay. Anyway, @patchfx is right and his workaround works

@thebracket
Copy link
Collaborator

I've applied this patch, it looks like it worked from here - thank you!

@nicolaracco
Copy link
Author

nicolaracco commented Aug 10, 2022

I'm not sure if it's strictly related to this issue or if I should open a new one, but when using two different consoles, each cls seems to "paint" in the background.
image

In this case, the console 0 draws a NAVY background, the console 1 just draws the player sprite, without setting any background. Each .cls() call seems to clear the sprite, but replacing it with a black background.

Is it expected or I'm missing something?

@bilowik
Copy link
Contributor

bilowik commented Aug 11, 2022

Yeah I think this poses an issue when Flexiconsole is not the bottom layer, it will leave permanent black bg on tiles that cover consoles under it. Changing the alpha values from 255 to 0 in those .cls() methods fixed that for me, but not sure if that's the correct fix or just happens to bandaid my specific issue.

Edit: Both FlexiConsole and SparseConsole only store tiles that actively have a glyph in them, so this change to the cls() function would mean tiles are only ever added or replaced with 'blanked out' tiles, slowly filling up the Vec?

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

Successfully merging a pull request may close this issue.

4 participants