0

请帮助解决几何问题。我正在创建轮子的多个扇区。现在我需要在每个扇区中放置从圆心到边缘的文本。但不知何故,一切都出了问题。

车轮

这是一个部门的类别:

package comps
{

    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.filters.GlowFilter;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Vector3D;
    import flash.net.URLRequest;
    import flash.text.AntiAliasType;
    import flash.text.Font;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;

    public class Sector extends Sprite
    {
        private var imageX1:Number;
        private var imageY1:Number;
        private var imageX2:Number;
        private var imageY2:Number;
        [Embed(source="font/SEGOEUIB.TTF", fontFamily="SegoeUI", mimeType="application/x-font", embedAsCFF="false", advancedAntiAliasing="true")]
        private var MoolEmbed:Class;

        public function Sector(tip:String, rot:Number, centerX:Number, centerY:Number, innerRadius:Number, outerRadius:Number, startAngle:Number, arcAngle:Number, val:Number, color:uint, alpha:Number, url:String, value:Number, steps:int=20)
        {
            Font.registerFont(MoolEmbed);

            var myArc:Sprite = new Sprite();
            myArc.graphics.lineStyle(2);
            myArc.graphics.beginFill(color, alpha);
            drawSolidArc (myArc,centerX, centerY, innerRadius, outerRadius, startAngle, arcAngle, url, steps);
            myArc.graphics.endFill();
            this.addChild(myArc);

                var myFormat:TextFormat = new TextFormat();
                myFormat.size = 20;
                myFormat.align = TextFormatAlign.CENTER;
                myFormat.font = 'SegoeUI';
                myFormat.bold = true;

                var myText:TextField = new TextField();
                myText.defaultTextFormat = myFormat;
                myText.setTextFormat(myFormat);
                myText.embedFonts = true;
                myText.antiAliasType = AntiAliasType.ADVANCED;
                myText.text = url;
                this.addChild(myText);

                myText.wordWrap = true;
                myText.width = outerRadius - innerRadius;
                myText.height = 20;
                var sectorsNum:Number = rot/360;
                textRotation(myText, rot*(sectorsNum-value) - rot*0.5, centerX, centerY);

                myText.x = imageX1 + 0 * (imageX2 - imageX1);
                myText.y = imageY1 + 0 * (imageY2 - imageY1);
                //trace (myText.x  + " " + myText.y);
                var myGlow:GlowFilter = new GlowFilter();
                myGlow.color = 0xFFFFFF; 
                myGlow.blurX = 20; 
                myGlow.blurY = 20; 
                myGlow.strength = 2;
                myText.filters = [myGlow];
            }
        }

        private function textRotation (target:TextField, angle:Number, centerX:Number, centerY:Number):void{
            var point:Point=new Point(centerX + target.width/2, centerY + target.height/2);

            var m:Matrix=target.transform.matrix;
            m.tx -= point.x;
            m.ty -= point.y;
            m.rotate (angle*(Math.PI/180));
            m.tx += point.x;
            m.ty += point.y;
            target.transform.matrix=m;
        }

        private function drawSolidArc (drawObj:Object, centerX:Number,centerY:Number,innerRadius:Number,outerRadius:Number,startAngle:Number,arcAngle:Number,url:String,steps:int=20):void {
            var twoPI:Number = 2 * Math.PI;
            var angleStep:Number = arcAngle/steps;
            var angle:Number, i:int, endAngle:Number;
            var xx:Number = centerX + Math.cos(startAngle * twoPI) * innerRadius;
            var yy:Number = centerY + Math.sin(startAngle * twoPI) * innerRadius;
            var xxInit:Number=xx;
            var yyInit:Number=yy;
            drawObj.graphics.moveTo(xx,yy);
            for(i=1; i<=steps; i++) {
                angle = (startAngle + i * angleStep) * twoPI;
                xx = centerX + Math.cos(angle) * innerRadius;
                yy = centerY + Math.sin(angle) * innerRadius;
                drawObj.graphics.lineTo(xx,yy);
                if (i==steps*0.5-1){
                    imageX1 = xx;
                    imageY1 = yy;
                }
            }
            endAngle = startAngle + arcAngle;
            for(i=0;i<=steps;i++) {
                angle = (endAngle - i * angleStep) * twoPI;
                xx = centerX + Math.cos(angle) * outerRadius;
                yy = centerY + Math.sin(angle) * outerRadius;
                drawObj.graphics.lineTo(xx,yy);
                if (i==steps*0.5){
                    imageX2 = xx;
                    imageY2 = yy;
                }
            }
            drawObj.graphics.lineTo(xxInit,yyInit);
        }
    }
}

这就是创造所有轮子:

sectorsNum = tarotAC.length;
                for (var i:int = 0; i < sectorsNum; i++){
                    var arcAngle:Number = - 1/sectorsNum;
                    var startAngle:Number = arcAngle*i;
                    var arc:Sector = new Sector(FlexGlobals.topLevelApplication.mode, 360/sectorsNum, 0, 0, stageW*0.1, stageW*0.5, startAngle, arcAngle, Number(sectorsNum - i), tarotAC.getItemAt(i).color, 1, tarotAC.getItemAt(i).datas, tarotAC.getItemAt(i).url);

                    con.addChild(arc);
                }
4

1 回答 1

1

通过查看它,我会说您的 TextFields 需要向上移动它们的高度。TextFields 是从顶部创建的,您给它们的坐标将更适合基线。也许您可以将 TextField 放入 Sprite 中,将 TextField 的 y 设置为 -height,然后操作容器而不是文本本身:

var container:Sprite = new Sprite();
container.addChild(myText);
this.addChild(container);
myText.y = -myText.height;
textRotation(container, rot*(sectorsNum-value) - rot*0.5, centerX, centerY);
//you should of course modify textRotation's first parameter type
container.x = imageX1 + 0 * (imageX2 - imageX1);
container.y = imageY1 + 0 * (imageY2 - imageY1);
于 2012-04-24T10:18:58.573 回答