Problems with color classes

Problems with color classes
0.0 0


I can’t seem to find the link to report issues/bugs on the site, and this should go there, but: I’m having problems with the color classes. Are Color4B and Color4F supposed to be interchangeable? Because when, for example, attempting to draw a cc.drawingUtil.SolidRect if I pass a Color4B it always draws white, but with Color4F it works fine…

Also, there’s a c4f method that equals to new Color4F, but there doesn’t seem to be a c4b analogous method, is that right or am I just missing it?


Yes, We didn’t check the type of parameter “color” in cc.drawingUtil.drawSolidRect, so if you pass a Color4B into the function, it’s also works, but it works bad.

Thank you for noticing, I think we need add this checking to these function, but it damages on performance.
And our document have flaged the type of these parameters.

Do you have any ideas?

Thanks a lot.


Dingping Lv wrote:

Do you have any ideas?

Well, I’m far from being a JS expert, but it sounds to me that what should be done is create a master, or rather, parent Color class and let it have all sorts of constructors (4b, 3b, 4f, 3f, etc - where the constructors with less parameters are just assuming opaciry at 100%), and use that parent class internally always for every method that needs information regarding colors, regardless of how the parameters were used for constructing the color object.

It smells like it may require quite a bit of refactoring ‘tho.
EDIT: another case in which having said color class would be usefull is when messing with “cc.drawingUtil.setDrawColor”, currently we only have “cc.drawingUtil.setDrawColor4B(r,g,b,a)” and “cc.drawingUtil.setDrawColor4F(r,g,b,a)”, but wouldn’t it be nice to have a “cc.drawingUtil.setDrawColor(color)” where ’color’ has been created with either c4f or c4b?