3

で問題が発生しDrawString()ましたXNA。私はSpriteBatchesいくつかの論理層に複数を使用しています。例:背景、オブジェクト、メニューなど。

メニューバッチでは、メニュー(背景の大きな灰色のボックス)、ボタン(メニューの小さな灰色のボックス)、およびボタンの文字列を描画します。

問題: http: //ompldr.org/vaGw4YQ/Unbenannt.png

しかし、何らかの理由で、文字列が完全に描画されていません。誰かが理由を知っていますか?

編集:

_menuLayer.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
        if (_menu != null)
        {
            _menuLayer.Draw(_menuBoard, new Vector2(graphics.PreferredBackBufferWidth / 2 - 160, graphics.PreferredBackBufferHeight / 2 - 240), Color.White);
        }
        _menuLayer.End();
        _buttonLayer.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
        if (_menu != null)
        {
            foreach (Button button in _menu.Buttons)
            {
                if (button.Pressed)
                {
                    _buttonLayer.Draw(_menuButtonPressed, button.Location, Color.White);
                    _buttonLayer.DrawString(_text, button.Text, button.GiveStringLocation(_text), Color.Black);
                }
                else
                {
                    _buttonLayer.Draw(_menuButton, button.Location, Color.White);
                    _buttonLayer.DrawString(_text, button.Text, button.GiveStringLocation(_text), Color.Black);
                }
            }
        }
        _buttonLayer.End();

<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
-->
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
  <Asset Type="Graphics:FontDescription">

    <!--
    Modify this string to change the font that will be imported.
    -->
    <FontName>Arial</FontName>

    <!--
    Size is a float value, measured in points. Modify this value to change
    the size of the font.
    -->
    <Size>20</Size>

    <!--
    Spacing is a float value, measured in pixels. Modify this value to change
    the amount of spacing in between characters.
    -->
    <Spacing>0</Spacing>

    <!--
    UseKerning controls the layout of the font. If this value is true, kerning information
    will be used when placing characters.
    -->
    <UseKerning>true</UseKerning>

    <!--
    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
    and "Bold, Italic", and are case sensitive.
    -->
    <Style>Bold</Style>

    <!--
    If you uncomment this line, the default character will be substituted if you draw
    or measure text that contains characters which were not included in the font.
    -->
    <!-- <DefaultCharacter>*</DefaultCharacter> -->

    <!--
    CharacterRegions control what letters are available in the font. Every
    character from Start to End will be built and made available for drawing. The
    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
    character set. The characters are ordered according to the Unicode standard.
    See the documentation for more information.
    -->
    <CharacterRegions>
      <CharacterRegion>
        <Start>&#32;</Start>
        <End>&#126;</End>
      </CharacterRegion>
    </CharacterRegions>
  </Asset>
</XnaContent>
4

3 に答える 3

2

フォントで特定の文字しか使用できないようです。

<CharacterRegions>
  <CharacterRegion>
    <Start>&#32;</Start>
    <End>&#126;</End>
  </CharacterRegion>
</CharacterRegions>

文字が開始タグと終了タグのASCII値の範囲内にあることを確認するか、開始タグと終了タグを変更して必要な文字を含めます。

http://www.asciitable.com/

于 2013-02-26T04:45:39.580 に答える
2

SpriteSortMode.Immediateを使用してみてください。そうでなければ、問題はあなたのやり方にあるのではないかと思います。UIの外部のクラスにレンダリングを任せるのは面倒なようです。あなたはボタンに描くように言うことができるはずです、そしてそれはそれ自身を描くべきです。または、実際にUIに描画するように指示すると、すべてのコントロールが描画され、子コントロールなどが描画されます。

そうすれば、UIを階層構造で構築できます::)

UIを少し構造化します。UIControlなどの基本クラスがあります。

List<UIControl> Children { get; protected set; }


Update(MyInputSystem input, float dt)
{
    UpdateChildren(input, dt);
}

UpdateChildren(MyInputSystem input, float dt)
{
    foreach(var child in Children)
        child.Update(input, dt);
}

Draw(SpriteBatch spriteBatch)
{
    DrawChildren(spriteBatch);
}

DrawChildren(SpriteBatch spriteBatch)
{
    foreach(var child in Children)
        child.Draw(spriteBatch);
}

次に、Panelクラスがあります。

class Panel: UIControl {

Vector2 Position { get; set; }
Texture2D Texture { get; set; }

override Draw(SpriteBatch spriteBatch)
{
    spriteBatch.Draw(Texture, Position, Color.White);
    base.Draw(spriteBatch);
}

}

次に、Labelクラスがあります。

class Label: Panel{

SpriteFont Font { get; set; }
String Text { get; set; }
Vector2 TextOffset { get; set; }
Color TextColor { get; set; }

override Draw(SpriteBatch spriteBatch)
{
    spriteBatch.Draw(Texture, Position, Color.White);
    spriteBatch.DrawString(Font, Text, Position + TextOffset,Text Color);
    DrawChildren(spriteBatch);
}

}

およびボタンクラス:

class Button: Label { //Inherit label, so we dont need to create som much new code

public event EventHandler<EventArgs> Click;

Rectangle _Bounds
public Rectangle Bounds
{
    get
    {
        if (_Rectangle.Width == 0)
            _Rectangle = new Rectangle((int)Position.X,(int)Position.Y, Texture.Width, Texture.Height);

        return _Texture;
    }
}

override Update(MyInputSystem input, flaot dt)
{
    if (input.MouseClicked && Bounds.Contains(input.MousePosition))
        Click(this, new EventArgs());
}

}

私がSpriteBatchを持っていないことに気づいたかもしれません。ここで開始/終了しますか?それは理由です:

class UI
{
List<UIControl> Controls;

Update(MyInputSystem input, flioat dt)
{
    foreach(var control in Controls)
       control.Update(input, dt);
}

Draw(SpriteBatch spriteBatch)
{
    spriteBatch.Begin(/*Parameters*/);
    foreach(var control in Controls)
       control.Draw(spriteBatch);
    spriteBatch.End();
}
}

私のドリフトをキャッチしますか?

于 2013-02-26T08:57:44.190 に答える
0

使用しているフォントに問題がある可能性があります。使用しているフォントが「.ttf」であることを確認し、いくつかの異なるフォントを試してください。Microsoftが推奨するフォントの1つを使用することを強くお勧めします。リンク: http: //go.microsoft.com/fwlink/?LinkId = 104778&clcid = 0x409

于 2013-02-26T01:01:54.337 に答える