ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

Add a new method: display.clearBlock() #134

Open Bozar opened 6 years ago

Bozar commented 6 years ago

Hi ondras, I'm wondering if it is possible to clear a block in the canvas?

function (x, y, width, height, fillText) {
    for (let i = x; i < x + width; i++) {
        for (let j = y; j < y + height; j++) {
            Rot.display.draw(i, j, fillText || ' ')    // space by default
        }
    }
} 
ondras commented 6 years ago

Just draw "nothing":

display.draw(x, y, "");

You can use an empty string, a space, a null value...

twpage commented 6 years ago

Does this work on a canvas with transparent background? I've never been able to do that, I always have to write a separately function to clear the canvas context directly. If you don't know off-hand I'll dig up some code and see if I can prove myself right (or wrong).

On Fri, Mar 2, 2018 at 7:40 AM, Ondřej Žára notifications@github.com wrote:

Just draw "nothing":

display.draw(x, y, "");

You can use an empty string, a space, a null value...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ondras/rot.js/issues/134#issuecomment-369910612, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCAEnTVbUd30VZGbxmpGmYkWonnCu-bks5taT2ygaJpZM4SZU8C .

-- Todd Page twpage@gmail.com

ondras commented 6 years ago

Does this work on a canvas with transparent background?

No, it does not. The canvas is never cleared, but rather drawn atop.

Implementing true clearing is a significantly complex task, because we also have hexagonal cells so the clearRect call is not sufficient here.

twpage commented 6 years ago

Thanks for the quick response! And yes, very good point about the hexes. My guess is it may be a fairly niche problem, so probably not worth a lot of effort. The work-around (for rectangles at least) is pretty easy.

On Thu, Mar 29, 2018 at 4:22 AM, Ondřej Žára notifications@github.com wrote:

Does this work on a canvas with transparent background?

No, it does not. The canvas is never cleared, but rather drawn atop.

Implementing true clearing is a significantly complex task, because we also have hexagonal cells so the clearRect call is not sufficient here.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ondras/rot.js/issues/134#issuecomment-377160628, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCAEkCNZI-fG2rnIYu9GPgg2C6OWhAiks5tjJmxgaJpZM4SZU8C .

-- Todd Page twpage@gmail.com