I just downloaded SFML.NET and added a referen开发者_Python百科ce 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?
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.
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
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.
精彩评论