Actionscript 3 对非矩形Healthbar进行编码

Actionscript 3 对非矩形Healthbar进行编码,actionscript-3,flash,Actionscript 3,Flash,我正在创建一个游戏,健康栏是在flash中使用actionscript完成的 如果酒吧只是矩形,我可以很容易地做到这一点,但它是一个不规则的形状,不知道如何 e、 g(画得不好) 谢谢 可以使用mask属性在不规则形状的对象上创建可见的移动边框。例如: class HealthBar extends Sprite { // implement normal healthbar draw, any shape allowed var m:Sprite; function H

我正在创建一个游戏,健康栏是在flash中使用actionscript完成的

如果酒吧只是矩形,我可以很容易地做到这一点,但它是一个不规则的形状,不知道如何

e、 g(画得不好)


谢谢

可以使用
mask
属性在不规则形状的对象上创建可见的移动边框。例如:

class HealthBar extends Sprite {
    // implement normal healthbar draw, any shape allowed
    var m:Sprite;
    function HealthBar() {
        m=new Sprite();
        m.graphics.beginFill(0x0,1);
        m.graphics.drawRect(0,0,100,50); // make sure it overlaps whole healthbar
        m.graphics.endFill();
        this.mask=m; // to set mask
        addChild(m); // necessary, otherwise it might not work properly
    }
    function adjustHealthBar(percentage:int):void {
        // will be called when you need to change the display
        // 0 = empty, 100 = full
        m.x=0-m.width*percentage/100; 
        // shift mask leftwards, so less of bar is visible
        // that's all! If you need fancy, redraw graphics of "m" for new healthbar state
    }
}

如果您使用的是flashide,那么您可以使用一个掩码创建一个movieclip。或者,您也可以完全根据值在代码中绘制它。您可以尝试在movieclip中使用不同的帧为每个健康栏绘制实际显示。在内部存储运行状况并根据运行状况掩码通过代码更新帧也是可能的,为此使用
mask
属性。