Using Javascript, I need to print a word over a canvas background (not a huge background, about 400 x 100 at the largest). The word has 3 parts (each a different colour). The word needs to change regularly (at its fastest, every 60 milliseconds or so, though it could be considerably slower than that too), and when it does the position of the word changes too. Word length is uncertain but could be long or short, and font size will vary from about 20 up to 40 points.
EDIT: Please note that I have tested doing everything on a single canvas and it's slower. This question is explicitly to address a background canvas (that sometimes changes a lot, sometimes not at all) with the text displayed in front of it in some way.
Am I better off doing the word on a second (smaller) canvas over the background canvas, or am I better off using HTML with perhaps a div containing spans for the colours, and updating the div's position and contents regularly?
Please note that ideally I need letter spacing, and have proposed the system outlined in Adding Letter Spacing in HTML Canvas
It seems to me that it's a matter of how slow measureText and fillText is, compared to the HTML DOM. My guess is that the Canvas system will be faster, even with the additional work of breaking down the font into characters to display.
Alternatively, if the system I proposed at the link given does NOT work then, on the canvas, I would just use three fillText() commands with different colors and texts, possibly with 3 measureText() commands too. How would that compare with the HTML div system?
Depending on the answers here I may create a test case and use jsperf to find out but I was wondering if I am missing anything obvious here?
To summarise, my three options are:
- Two canvases, with the method proposed at Adding Letter Spacing in HTML Canvas
- Two canvases, with 3 fillText() commands with different colors and texts, possibly with 3 measureText() commands too
- One canvas and one HTML overlay comprising a div with two spans inside it
Which is better? Any thoughts or knowledge on this?