如何在不改变边框颜色的情况下改变精灵的颜色?
我有这段代码
public function TalentBox(x:int, y:int, arg_color:int = 0xFFFFFF):void
{
this.graphics.beginFill(arg_color);
this.graphics.lineStyle(1.0, 0x000000, 0.7);
this.graphics.drawRect(0, 0, 7, 13);
this.alpha = 1.0;
this.x = x;
this.y = y;
this.graphics.endFill();
}
,我在其中构造类(从精灵扩展)。然后我需要一个改变精灵颜色的函数。目前我有这个
public function setColor(arg_color:int):void
{
color = arg_color;
this.graphics.beginFill(color);
this.graphics.drawRect(0, 0, 7, 13);
this.graphics.endFill();
}
,它似乎可以工作,但这正在创建一个新的矩形。这是我不想要的。
我尝试过 ColorTransform,这改变了一切,甚至是边框,这不是我想要的。我无法进行颜色转换然后设置边框颜色。
那么如何在不改变边框颜色的情况下改变精灵的颜色呢?
I have this code
public function TalentBox(x:int, y:int, arg_color:int = 0xFFFFFF):void
{
this.graphics.beginFill(arg_color);
this.graphics.lineStyle(1.0, 0x000000, 0.7);
this.graphics.drawRect(0, 0, 7, 13);
this.alpha = 1.0;
this.x = x;
this.y = y;
this.graphics.endFill();
}
Where I construct the class (that extends from sprite). Then I need to have a function that changes the color of the sprite. Currently I have this
public function setColor(arg_color:int):void
{
color = arg_color;
this.graphics.beginFill(color);
this.graphics.drawRect(0, 0, 7, 13);
this.graphics.endFill();
}
And It seems to work but this is creating a new rect. Which I do not want.
And I have tried ColorTransform, and that changes everything, even the border, which is not what I wanted. And I am not able to colortransform and then set the border color.
So how can I change the color of a sprite without changing the border color?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到答案了。
您在类中创建了两个精灵。身体和边界。单独设置它们,然后仅在身体精灵上使用变换更改颜色。
这是修改后的构造函数
I have found the answer.
You create two sprites in the class. The body and the border. Set those individually and then change the color with transform only on the body sprite.
Here is the modified constructor