如何在不改变边框颜色的情况下改变精灵的颜色?

发布于 2024-09-07 19:22:39 字数 721 浏览 0 评论 0原文

我有这段代码

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2024-09-14 19:22:39

我已经找到答案了。

您在类中创建了两个精灵。身体和边界。单独设置它们,然后仅在身体精灵上使用变换更改颜色。

这是修改后的构造函数

public function TalentBox(x:int, y:int, arg_color:int = 0xFFFFFF):void
{
    body.graphics.beginFill(arg_color);
    body.graphics.drawRect(x + 1, y + 1, 6, 12);
    body.graphics.endFill();

    border.graphics.beginFill(0xFFFFFF);
    border.graphics.lineStyle(1.0, 0x000000, 0.7);
    border.graphics.drawRect(x, y, 7, 13);
    border.graphics.endFill();

    this.addChild(border);
    this.addChild(body);
}

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

public function TalentBox(x:int, y:int, arg_color:int = 0xFFFFFF):void
{
    body.graphics.beginFill(arg_color);
    body.graphics.drawRect(x + 1, y + 1, 6, 12);
    body.graphics.endFill();

    border.graphics.beginFill(0xFFFFFF);
    border.graphics.lineStyle(1.0, 0x000000, 0.7);
    border.graphics.drawRect(x, y, 7, 13);
    border.graphics.endFill();

    this.addChild(border);
    this.addChild(body);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文