简单地说,我想设置几个不同的特定颜色,然后在他们身上涂点颜色。
var color1 = new ColorTransform(); color1.color = 0x0000FF;
var color2 = new ColorTransform(); color2.color = 0x00FF00;
var color3 = new ColorTransform(); color3.color = 0xFFFF00;
thing1.transform.colorTransform = color1;
thing2.transform.colorTransform = color2;
thing3.transform.colorTransform = color3;
thing1.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 200, 150, 0);
thing2.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 200, 150, 0);
thing3.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0, 200, 150, 0);不幸的是,颜色转换会重置值。有办法保留第一个颜色变换的值吗?
发布于 2022-04-22 05:00:29
我找到了解决这个问题的办法。
如果我将对象设置为颜色
var color1 = new ColorTransform(); color1.color = 0x0000FF;
thing1.transform.colorTransform = color1;然后,我可以编辑蓝色和绿色的值,以便得到我想要的颜色。
color1.blueOffset+=200;
color1.greenOffset+=150;然后对对象使用颜色转换来设置新颜色。
thing1.transform.colorTransform = color1;发布于 2022-04-22 02:52:15
您应该能够使用ColorTransform.concat()函数来完成这个任务。
var color1 = new ColorTransform(); color1.color = 0x0000FF;
var color2 = new ColorTransform(); color2.color = 0x00FF00;
var color3 = new ColorTransform(); color3.color = 0xFFFF00;
color1.concat( new ColorTransform(1, 1, 1, 1, 0, 200, 150, 0) );
color2.concat( new ColorTransform(1, 1, 1, 1, 0, 200, 150, 0) );
color3.concat( new ColorTransform(1, 1, 1, 1, 0, 200, 150, 0) );
thing1.transform.colorTransform = color1;
thing2.transform.colorTransform = color2;
thing3.transform.colorTransform = color3;它本质上与(使用Math.min将偏移值夹紧到255个)相同:
thing1.transform.colorTransform = new ColorTransform(1*1, 1*1, 1*1, 1*1, Math.min(0x00+0, 0xFF), Math.min(0x00+200, 0xFF), Math.min(0xFF+150, 0xFF), Math.min(0x00+0, 0xFF));
thing2.transform.colorTransform = new ColorTransform(1*1, 1*1, 1*1, 1*1, Math.min(0x00+0, 0xFF), Math.min(0xFF+200, 0xFF), Math.min(0x00+150, 0xFF), Math.min(0x00+0, 0xFF));
thing3.transform.colorTransform = new ColorTransform(1*1, 1*1, 1*1, 1*1, Math.min(0xFF+0, 0xFF), Math.min(0xFF+200, 0xFF), Math.min(0x00+150, 0xFF), Math.min(0x00+0, 0xFF));或者:
thing1.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0x00, 0xC8, 0xFF, 0x00);
thing2.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0x00, 0xFF, 0x96, 0x00);
thing3.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 0xFF, 0xFF, 0x96, 0x00);https://stackoverflow.com/questions/71962848
复制相似问题