示例#1
0
        /// <summary>
        /// 绘制字符串
        /// </summary>
        /// <param name="str">将要绘画的字符串</param>
        /// <param name="x">首字的对应显示坐标x</param>
        /// <param name="y">首字的对应显示坐标y</param>
        /// <param name="percent">字体显示的百分比(高度参照24,宽度自适应)</param>
        /// <param name="distance">字间的间距</param>
        /// <param name="ColMax">每行最多能显示的字的数量</param>
        public virtual void DrawString(Renderer renderer, string str, double x, double y, float percent,
                                       float distance, int ColMax)
        {
            if (!Binded)
            {
                throw new Exception("当前工具没有绑定字体");
            }
            Sprite sprite;

            Char[] Arr        = str.ToCharArray();
            int    count      = Arr.Length;
            int    offsetx    = 0;
            int    offsety    = 0;
            float  h_distance = percent * 24;

            for (int i = 0; i < count; i++)
            {
                string s = Arr[i].ToString();
                if (s == "\n")
                {
                    offsetx = 0;
                    offsety++;
                    continue;
                }
                else if (s == " ")
                {
                }
                else
                {
                    sprite = SelectFont.GetAci(s);
                    sprite.SetWidth((float)sprite.GetWidth() * percent);
                    sprite.SetHeight((float)sprite.GetHeight() * percent);
                    sprite.SetPosition(x + offsetx * distance, y - offsety * h_distance);
                    renderer.DrawSprite(sprite);
                }
                offsetx++;
                if (offsetx >= ColMax)
                {
                    offsetx = 0;
                    offsety++;
                }
            }
        }
示例#2
0
        //     提供文本 , 坐标 , 字间距离
        void DrawText(string text, float _x, float _y, float dw)
        {
            int    len = text.Length;
            Sprite spr;

            for (int i = 0; i < len; i++)
            {
                // spr = NumCharactors[text.Substring(i, 1)];
                spr = textfont.GetAci(text.Substring(i, 1));
                spr.SetHeight(charactorwidth);
                spr.SetWidth(charactorheight);
                spr.SetPosition(new Vector(_x + charactorwidth / 2 + i * dw, _y, 0));
                //spr.SetColor(new Color(1, 1, 1, Alpha));
                renderer.DrawSprite(spr);
            }
        }