首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >双色变换在AS3中的应用

双色变换在AS3中的应用
EN

Stack Overflow用户
提问于 2022-04-22 02:32:37
回答 2查看 42关注 0票数 1

简单地说,我想设置几个不同的特定颜色,然后在他们身上涂点颜色。

代码语言:javascript
复制
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);

不幸的是,颜色转换会重置值。有办法保留第一个颜色变换的值吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-04-22 05:00:29

我找到了解决这个问题的办法。

如果我将对象设置为颜色

代码语言:javascript
复制
var color1 = new ColorTransform(); color1.color = 0x0000FF;
thing1.transform.colorTransform = color1;

然后,我可以编辑蓝色和绿色的值,以便得到我想要的颜色。

代码语言:javascript
复制
color1.blueOffset+=200;
color1.greenOffset+=150;

然后对对象使用颜色转换来设置新颜色。

代码语言:javascript
复制
thing1.transform.colorTransform = color1;
票数 1
EN

Stack Overflow用户

发布于 2022-04-22 02:52:15

您应该能够使用ColorTransform.concat()函数来完成这个任务。

代码语言:javascript
复制
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个)相同:

代码语言:javascript
复制
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));

或者:

代码语言:javascript
复制
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);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71962848

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档