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.34k stars 255 forks source link

Added support for foreground coloring to tile.js #22

Closed troygilbert closed 9 years ago

ondras commented 10 years ago

Thanks for the code!

I have not studied it thoroughly, but I see you use a per-pixel approach. This is known to be painfully slow. Are you aware of the "globalCompositeOperation" feature of HTML5 2d canvas?

We might be basically able to tint stuff at a native (=faster) level by some clever combination of opacity, globalCompositeOperation and drawing order. You can read some more on this topic at:

http://stackoverflow.com/questions/2688961/how-do-i-tint-an-image-with-html5-canvas http://www.playmycode.com/blog/2011/06/realtime-image-tinting-on-html5-canvas/ http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.png

Also, I see that your code assumes only one foreground color. I am not sure how this fits into common scenarios, such as "poisoned being standing on a floor tile", where you actually want to colorize/tint only some of the tiles in the drawn stack. I am afraid that this introduces another level of complexity, such as specifying the foreground color as an array. What if these two arrays (fg/ch) differ in length? What about falsy values in "fg" array; does that mean "no tinting!" or rather "tint with the default foreground color!" ?

This being said, I am afraid I won't be able to finalize and merge this code during Christmas. I plan to be offline most of the time, so please excuse my delayed responses. Hope you are not in a hurry for this :-)

troygilbert commented 10 years ago

Yes, the per-pixel method was the best option I'd found for arbitrary color transformation, but the top answer to the stack overflow link you posted mentions a technique that works great for my case where all I want is the alpha from my tiles and want just the foreground color, basically reproducing how fonts work. Do you think we should use that approach?

And I should update to accepting a foreground color array, and if the array is not complete then it's just like the foreground color isn't specified (like the current logic, unmodified sprite copying).

No problem about the delays, I've got everything working for my needs on my end.

ondras commented 9 years ago

Proper tile coloring/tinting was implemented in #50.