Flashpunk中的Word Wrap问题

时间:2013-03-21 23:38:41

标签: actionscript-3 flash word-wrap

由于某种原因,我的wordwrap的最后一行不显示

public class ShopButton extends Entity 
{

    private var callback:Function = null;
    public var buttonText:String = "";
    public var textImage:Text;
    public var picture:BitmapData = new BitmapData(100, 100, true, 1);
    public var boxImage:Stamp;
    public var displayImage:Graphiclist;
    public var displayImage2:Graphiclist;

    public var tooltipPicture:BitmapData = new BitmapData(150, 130, true, 1);
    public var tooltipBox:Stamp;
    public var tooltipText:Array = [];
    public var tooltipString:Array = [];


    public var buttonWidth:int = 100;
    public var buttonHeight:int = 100;

    private var clicked:Boolean = false;
    private var shiftClicked:Boolean = false;
    private var hovered:Boolean = false;
    private var fontSize:int = 16;

    public var label:String = "";

    public function ShopButton(x:int = 0, y:int = 0, label:String = "", callback:Function = null) 
    {
        this.callback = callback;
        this.label = label;
        buttonText = label;

        textImage = new Text(buttonText, 5, 5, { width:buttonWidth-10, wordWrap:true, align:"center", size:fontSize, font:"Abscissa" } );
        Draw.setTarget(picture);
        Draw.rectPlus(0, 0, buttonWidth, buttonHeight, 0x000000, 1, true, 2, 5);
        Draw.rectPlus(0, 0, buttonWidth, buttonHeight, 0xFFFF00, 1, false, 5, 5);

        boxImage = new Stamp(Assets.SHOPBUTTON);
        textImage.y = (boxImage.height / 2) - (textImage.height / 2);

        displayImage = new Graphiclist(boxImage, textImage);

        super (x, y, displayImage);

        setHitboxTo(boxImage);

        Draw.setTarget(tooltipPicture);
        Draw.rectPlus(0, 0, 150, 130, 0x000000, 1, true, 1, 0);
        Draw.rectPlus(0, 0, 150, 130, 0xFFFF00, 1, false, 5, 0);

        tooltipBox = new Stamp(Assets.SHOPBUTTONBORDER);

        updateTooltip();
    }

    public function updateTooltip():void
    {
        var minDamage:int = 0;
        var maxDamage:int = 0;
        var damageResist:int = 0;

        switch(label)
        {
            case "Purchase Ammo":
                tooltipString[0] = "";
                tooltipString[1] = "Purchase more";
                tooltipString[2] = "shurikens";
                tooltipString[3] = "";
                tooltipString[4] = "Shift + Click";
                tooltipString[5] = "To buy max";
                break;
            case "Upgrade Melee Weapon":
                minDamage = Globals.meleeDamage[0][Globals.meleeLevel];
                maxDamage = Globals.meleeDamage[1][Globals.meleeLevel];
                minDamage = minDamage * (1+(Globals.playerMeleeDamage / 100));
                maxDamage = maxDamage * (1 + (Globals.playerMeleeDamage / 100));
                tooltipString[0] = "Current Level";
                tooltipString[1] = "Damage: "
                tooltipString[2] = "" + minDamage + " - " + maxDamage;
                tooltipString[3] = "Next Level";
                if (Globals.meleeLevel < Globals.meleeMaxLevel)
                {
                    minDamage = Globals.meleeDamage[0][Globals.meleeLevel + 1];
                    maxDamage = Globals.meleeDamage[1][Globals.meleeLevel + 1];
                    minDamage = minDamage * (1+(Globals.playerMeleeDamage / 100));
                    maxDamage = maxDamage * (1 + (Globals.playerMeleeDamage / 100));
                    tooltipString[4] = "Damage: "
                    tooltipString[5] = "" + minDamage + " - " + maxDamage;
                }
                else 
                {
                    tooltipString[4] = "";
                    tooltipString[5] = "Max Level";
                }
                break;
            case "Upgrade Ranged Weapon":
                minDamage = Globals.rangedDamage[0][Globals.rangedLevel];
                maxDamage = Globals.rangedDamage[1][Globals.rangedLevel];
                minDamage = minDamage * (1+(Globals.playerRangeDamage / 100));
                maxDamage = maxDamage * (1 + (Globals.playerRangeDamage / 100));
                tooltipString[0] = "Current Level";
                tooltipString[1] = "Damage: "
                tooltipString[2] = "" + minDamage + " - " + maxDamage;
                tooltipString[3] = "Next Level";
                if (Globals.rangedLevel < Globals.rangedMaxLevel)
                {
                    minDamage = Globals.rangedDamage[0][Globals.rangedLevel + 1];
                    maxDamage = Globals.rangedDamage[1][Globals.rangedLevel + 1];
                    minDamage = minDamage * (1+(Globals.playerRangeDamage / 100));
                    maxDamage = maxDamage * (1 + (Globals.playerRangeDamage / 100));
                    tooltipString[4] = "Damage: "
                    tooltipString[5] = "" + minDamage + " - " + maxDamage;
                }
                else 
                {
                    tooltipString[4] = "";
                    tooltipString[5] = "Max Level";
                }
                break;
            case "Upgrade Armor":
                damageResist = Globals.armorDefense[Globals.armorLevel];
                damageResist = damageResist * (1 + (Globals.playerDefense / 100));
                tooltipString[0] = "Current Level";
                tooltipString[1] = "Damage Resist: "
                tooltipString[2] = "" + damageResist;
                tooltipString[3] = "Next Level";
                if (Globals.armorLevel < Globals.armorMaxLevel)
                {
                    damageResist = Globals.armorDefense[Globals.armorLevel + 1];
                    damageResist = damageResist * ( 1 + (Globals.playerDefense / 100));
                    tooltipString[4] = "Damage Resist: "
                    tooltipString[5] = "" + damageResist;
                }
                else 
                {
                    tooltipString[4] = "";
                    tooltipString[5] = "Max Level";
                }
                break;
        }

        tooltipText[0] = new Text(tooltipString[0], 0, 10, {width:150, align:"center", size:fontSize, font:"Abscissa"});
        tooltipText[0].x = -25;
        tooltipText[0].y -= 20;
        tooltipText[1] = new Text(tooltipString[1], 0, 30, {width:150, align:"center", size:fontSize, font:"Abscissa"});
        tooltipText[1].x = -25;
        tooltipText[1].y -= 20;
        tooltipText[2] = new Text(tooltipString[2], 0, 45, {width:150, align:"center", size:fontSize, font:"Abscissa"});
        tooltipText[2].x = -25;
        tooltipText[2].y -= 20;
        tooltipText[3] = new Text(tooltipString[3], 0, 65, {width:150, align:"center", size:fontSize, font:"Abscissa"});
        tooltipText[3].x = -25;
        tooltipText[3].y -= 20;
        tooltipText[4] = new Text(tooltipString[4], 0, 85, {width:150, align:"center", size:fontSize, font:"Abscissa"});
        tooltipText[4].x = -25;
        tooltipText[4].y -= 20;
        tooltipText[5] = new Text(tooltipString[5], 0, 100, {width:150, align:"center", size:fontSize, font:"Abscissa"});
        tooltipText[5].x = -25;
        tooltipText[5].y -= 20;

        tooltipBox.x = -25;
        tooltipBox.y = -20;

        displayImage2 = new Graphiclist(tooltipBox, tooltipText[0], tooltipText[1], tooltipText[2], tooltipText[3], tooltipText[4], tooltipText[5]);

    }

    public function click(action:String = ""):void
    {
        //trace(action);
        if (action == "Shift" && label == "Purchase Ammo" && callback != null) callback("Shift");
        else if (callback != null) callback();
    }

    override public function update():void
    {
        super.update();
        if (collidePoint(x, y, world.mouseX, world.mouseY))
        {
            if (Input.mousePressed && !Input.check(Key.SHIFT))
            {
                shiftClicked = false;
                clicked = true;
            }
            if (Input.mousePressed && Input.check(Key.SHIFT))
            {
                //trace ("Shifty");
                clicked = false;
                shiftClicked = true;
            }
            if (Input.mouseReleased && clicked) click("");
            if (Input.mouseReleased && shiftClicked) click("Shift");
            hovered = true;
        }
        else hovered = false;

        if (Input.mouseReleased) clicked = false;

        if (hovered) 
        {
            updateTooltip();
            graphic = displayImage2;
        }
        else graphic = displayImage;
    }

}

当我运行它时,它会显示除最后一行文本之外的所有内容(我想我需要一个10的代表来发布截图)。例如,第一个按钮显示“购买”而不是“购买Ammo”。

以前有没有人遇到过这个问题,如果有的话,你怎么解决它?

2 个答案:

答案 0 :(得分:0)

我在自动换行方面遇到了一些问题。似乎对于Text类,当您指定其宽度和高度然后将自动换行设置为true且重要时,自动换行可正常工作 - 可调整为false。

答案 1 :(得分:0)

我只是遇到了完全相同的问题,尝试设置高度属性,这对我来说已经解决了。