문제

In a card game I use a TextField in the middle to display the playing table number, but also to detect if a playing card has been played - using myTextField.hitTestObject(myCard) - which means the TextField's position and dimensions may not change:

enter image description here

My current AS3 code is:

        var format:TextFormat = new TextFormat();
        format.color = 0xFFFFFF;
        format.size = 30;
        format.bold = true;

        myTextField.defaultTextFormat = format;
        myTextField.border = true;
        myTextField.borderColor = 0xFFFFFF;
        myTextField.x = W/2-Card.W/2;
        myTextField.y = Card.H;
        myTextField.width = Card.W;
        myTextField.height = Card.H/4;

        addChild(myTextField);

However the TextField's content (the String "#2029" in the above screenshot) is not in the center of it.

I can not set _middle.autoSize = TextFieldAutoSize.CENTER because this changes the width of the border and breaks hitTestObject().

Is there another way to align the text in the middle please?

도움이 되었습니까?

해결책

Set the align property of TextFormat.

format.align = TextFormatAlign.CENTER;

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top