Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

When drawing vector graphics in the canvas you set the fillStyle using an rgba string like this...

context.fillStyle = "rgba(255, 223, 191, 1)";

Is it possible to feed in a javascript object instead (or just numbers). Seems silly that I would need to construct a string to feed to this value if I wanted the color dynamic.

context.fillStyle = "rgba(255, 223, 191, " + alpha + ")";

The specification clearly says "a CSS Color string" but it seems crazy. Am I missing something?

http://www.w3.org/TR/2dcontext/#fill-and-stroke-styles

update: I switched to using globalAlpha for this specific example. But still seems crazy.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Nope, you're not missing anything. This has to be a string, containing a valid CSS color value.

To reassure you, you're not the first one wondering why so much hate.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.