javascript - When using "destination-in," only the last thing drawn seems to render -
i'm making little library emulate curses-like interface in javascript using bitmap font. font png characters in it, , transparent background.
the method i'm using render character follows.
- draw square on space character going go. square foreground color of character
- change
context.globalcompositeoperation
destination-in
- draw character on square
this done in function called putchar
. reason, though, last putchar
call seems render.
in following jsfiddle, i've removed library except what's needed reproduce issue. putchar
called in lines 56, 57, , 58. should render yellow "a", green "b", , blue "c" in row. third putchar
call rendered (the blue "c".)
this first time using composite operations, must missing something. know why might happening?
from http://www.html5canvastutorials.com/advanced/html5-canvas-global-composite-operations-tutorial/
it's important note canvas context can support 1 composite operation throughout life cycle. if want use multiple composite operations, tutorial does, need apply operations on hidden canvas , copy results onto visible canvas.
so, approach may have use 2 canvases , blit portion of 1 onto other each character.
Comments
Post a Comment