如何在 SFML.NET 中使用文本?

发布于 2024-09-14 03:47:54 字数 282 浏览 6 评论 0原文

我刚刚下载了 SFML.NET 并添加了对其中包含的库 DLL 的引用,但似乎 Text 类不存在。在网站上的示例中,很明显正在使用 Text 对象......因此该示例将无法编译。亲自看看...

替代文本 http://filebox.me/files/5gubdwfcr_helpme.png

只有字体,没有文字!有人知道我可能做错了什么吗?

I just downloaded SFML.NET and added a reference to the library DLLs included with it, but it seems the Text class is not there. In the example on the site, it is clear that a Text object being used... so the example won't compile. See for yourself...

alt text http://filebox.me/files/5gubdwfcr_helpme.png

There's only Font, no Text! Anyone knows what I could be doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

地狱即天堂 2024-09-21 03:47:54

您可能正在查看 2.x 示例,其中 String2D 已被删除并替换为 Text。
String2D 适用于 1.x,您可以使用 Text 属性来更改它显示的内容。

幸运的是,这些接口非常相似。您应该能够简单地将声明为 Text 的任何内容替换为 String2D,并将 Text 属性更改为 DisplayedString,而无需更改任何其他代码。每个版本的示例:

VB.Net

SFML.NET 1.x

 Imports SFML
 Imports SFML.Window
 Imports SFML.Graphics

  Public Sub Main()
   Dim Output As New RenderWindow(New VideoMode(640, 480), "SFML.NET Text Example")

   Dim ExampleText As New String2D("", New Font("myfont.tff"))    
   ExampleText.Position = New Vector2(5, 5)

   Do While (true)
    Output.Clear(New SFML.Graphics.Color(0,128,160))
    ExampleText.Text= String.Format("Hello, world! {0}", DateTime.Now.ToString("hh:MM.ss"))
    Output.Draw(ExampleText)
    Output.Display()
   End While

   End Sub

SFML.NET 2.x

 Imports SFML
 Imports SFML.Window
 Imports SFML.Graphics

  Public Sub Main()
   Dim Output As New RenderWindow(New VideoMode(640, 480), "SFML.NET Text Example")

   Dim ExampleText As New Text("", New Font("myfont.tff"))    
   ExampleText.Position = New Vector2(5, 5)

   Do While (true)
    Output.Clear(New SFML.Graphics.Color(0,128,160))
    ExampleText.DisplayedString = String.Format("Hello, world! {0}", DateTime.Now.ToString("hh:MM.ss"))
    Output.Draw(ExampleText)
    Output.Display()
   End While

   End Sub

C#

SFML.NET 1.x

using SFML;
using SFML.Window;
using SFML.Graphics;

public void Main()
{
    var output = new RenderWindow(new VideoMode(640, 480), "SFML.NET Text Example");

    var exampleText = new String2D("", new Font("myfont.tff"));
    exampleText.Position = new Vector2(5, 5);

    while(true)
    {
        var timestamp = DateTime.Now.ToString("hh:MM.ss");
        output.Clear(new SFML.Graphics.Color(0, 128, 160));
        exampleText.Text = $"Hello, world! {timestamp}";
        output.Draw(exampleText);
        output.Display();
    }
}

SFML.NET 2.x

using SFML;
using SFML.Window;
using SFML.Graphics;

public void Main()
{
    var output = new RenderWindow(new VideoMode(640, 480), "SFML.NET Text Example");

    var exampleText = new Text("", new Font("myfont.tff"));
    exampleText.Position = new Vector2(5, 5);

    while(true)
    {
        var timestamp = DateTime.Now.ToString("hh:MM.ss");
        output.Clear(new SFML.Graphics.Color(0, 128, 160));
        exampleText.DisplayedString = $"Hello, world! {timestamp}";
        output.Draw(exampleText);
        output.Display();
    }
}

显然是非常简单的例子,但希望能够展示差异有多么简单。

You are probably looking at 2.x samples where String2D has been removed and replaced with Text.
String2D is for 1.x, and you use the Text property to change what it displays.

Fortunately the interfaces are very similar. You should be able to simply replace anything declared as Text with String2D and change the Text property to DisplayedString without changing any of the other code. An example for each version:

VB.Net

SFML.NET 1.x

 Imports SFML
 Imports SFML.Window
 Imports SFML.Graphics

  Public Sub Main()
   Dim Output As New RenderWindow(New VideoMode(640, 480), "SFML.NET Text Example")

   Dim ExampleText As New String2D("", New Font("myfont.tff"))    
   ExampleText.Position = New Vector2(5, 5)

   Do While (true)
    Output.Clear(New SFML.Graphics.Color(0,128,160))
    ExampleText.Text= String.Format("Hello, world! {0}", DateTime.Now.ToString("hh:MM.ss"))
    Output.Draw(ExampleText)
    Output.Display()
   End While

   End Sub

SFML.NET 2.x

 Imports SFML
 Imports SFML.Window
 Imports SFML.Graphics

  Public Sub Main()
   Dim Output As New RenderWindow(New VideoMode(640, 480), "SFML.NET Text Example")

   Dim ExampleText As New Text("", New Font("myfont.tff"))    
   ExampleText.Position = New Vector2(5, 5)

   Do While (true)
    Output.Clear(New SFML.Graphics.Color(0,128,160))
    ExampleText.DisplayedString = String.Format("Hello, world! {0}", DateTime.Now.ToString("hh:MM.ss"))
    Output.Draw(ExampleText)
    Output.Display()
   End While

   End Sub

C#

SFML.NET 1.x

using SFML;
using SFML.Window;
using SFML.Graphics;

public void Main()
{
    var output = new RenderWindow(new VideoMode(640, 480), "SFML.NET Text Example");

    var exampleText = new String2D("", new Font("myfont.tff"));
    exampleText.Position = new Vector2(5, 5);

    while(true)
    {
        var timestamp = DateTime.Now.ToString("hh:MM.ss");
        output.Clear(new SFML.Graphics.Color(0, 128, 160));
        exampleText.Text = $"Hello, world! {timestamp}";
        output.Draw(exampleText);
        output.Display();
    }
}

SFML.NET 2.x

using SFML;
using SFML.Window;
using SFML.Graphics;

public void Main()
{
    var output = new RenderWindow(new VideoMode(640, 480), "SFML.NET Text Example");

    var exampleText = new Text("", new Font("myfont.tff"));
    exampleText.Position = new Vector2(5, 5);

    while(true)
    {
        var timestamp = DateTime.Now.ToString("hh:MM.ss");
        output.Clear(new SFML.Graphics.Color(0, 128, 160));
        exampleText.DisplayedString = $"Hello, world! {timestamp}";
        output.Draw(exampleText);
        output.Display();
    }
}

Obviously a very stripped back example but hopefully demonstrates just how simple the difference is.

猫七 2024-09-21 03:47:54

在最新的 SFML.net 中有 Text 类。使用与 C++ 中的相同,只是您必须处理 C# properties

In newest SFML.net there is Text class. The use is the same as in C++ except that You have to deal with C# properties

痴者 2024-09-21 03:47:54

您可能想使用 String2D 类(文档中的 String 类)实际绘制文本。 教程中这个类的变量叫做Text,即可能你感到困惑的地方。

You probably want to use the String2D class (the String class in the documentation) to actually draw text. The variable of this class in the tutorial is called Text, which is probably where you were confused.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文