2010-07-01 80 views
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,它改變了一切,甚至邊界,這不是我想要的。而且我不能colortransform然後設置邊框顏色。

那麼如何在不改變邊框顏色的情況下更改精靈的顏色?

回答

0

我找到了答案。

您可以在課堂上創建兩個精靈。身體和邊界。單獨設置這些顏色,然後僅在身體精靈中使用變換來更改顏色。

下面是修改的構造

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); 
}