2009-01-29 00:18:34 +08:00
< h2 > Welcome< / h2 >
< p >
Welcome to the official SFML.Net documentation. Here you will find a detailed
description of all the SFML.Net classes. < br / >
If you are looking for tutorials, help or whatever, you can visit the official website
at < a href = "http://www.sfml-dev.org/" > www.sfml-dev.org< / a > .
< / p >
< h2 > Short example< / h2 >
< p >
Here is a short example in C#, to show you how simple it is to use SFML.Net :
< / p >
< pre style = "background-color:#F0F0F0" >
< span style = "color:blue" > using< / span > System;
< span style = "color:blue" > using< / span > SFML.Audio;
< span style = "color:blue" > using< / span > SFML.Window;
< span style = "color:blue" > using< / span > SFML.Graphics;
< span style = "color:blue" > namespace< / span > Example
{
< span style = "color:blue" > class< / span > < span style = "color:#2B91AF" > Program< / span >
{
< span style = "color:blue" > static void< / span > OnClose(< span style = "color:blue" > object< / span > sender, < span style = "color:#2B91AF" > EventArgs< / span > e)
{
< span style = "color:#008000" > // Close the window when OnClose event is received< / span >
< span style = "color:#2B91AF" > RenderWindow< / span > window = (< span style = "color:#2B91AF" > RenderWindow< / span > )sender;
window.Close();
}
< span style = "color:blue" > static void< / span > Main(< span style = "color:blue" > string< / span > [] args)
{
< span style = "color:#008000" > // Create the main window< / span >
2010-01-30 06:10:15 +08:00
< span style = "color:#2B91AF" > RenderWindow< / span > window = < span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > RenderWindow< / span > (< span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > VideoMode< / span > (800, 600), < span style = "color:#A31515" > "SFML window"< / span > );
window.Closed += < span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > EventHandler< / span > (OnClose);
2009-01-29 00:18:34 +08:00
< span style = "color:#008000" > // Load a sprite to display< / span >
< span style = "color:#2B91AF" > Image< / span > image = < span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > Image< / span > (< span style = "color:#A31515" > "cute_image.jpg"< / span > );
< span style = "color:#2B91AF" > Sprite< / span > sprite = < span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > Sprite< / span > (image);
< span style = "color:#008000" > // Create a graphical string to display< / span >
2010-01-30 06:10:15 +08:00
< span style = "color:#2B91AF" > Font< / span > font = < span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > Font< / span > (< span style = "color:#A31515" > "arial.ttf"< / span > );
< span style = "color:#2B91AF" > Text< / span > text = < span style = "color:blue" > new< / span > < span style = "color:#2B91AF" > Text< / span > (< span style = "color:#A31515" > "Hello SFML.Net"< / span > , font);
2009-01-29 00:18:34 +08:00
< span style = "color:#008000" > // Load a music to play< / span >
< span style = "color:#2B91AF" > Music< / span > music = < span style = "color:blue" > new< / span > Music(< span style = "color:#A31515" > "nice_music.ogg"< / span > );
music.Play();
< span style = "color:#008000" > // Start the game loop< / span >
2010-01-30 06:10:15 +08:00
< span style = "color:blue" > while< / span > (window.IsOpened())
2009-01-29 00:18:34 +08:00
{
< span style = "color:#008000" > // Process events< / span >
2010-01-30 06:10:15 +08:00
window.DispatchEvents();
2009-01-29 00:18:34 +08:00
< span style = "color:#008000" > // Clear screen< / span >
2010-01-30 06:10:15 +08:00
window.Clear();
2009-01-29 00:18:34 +08:00
< span style = "color:#008000" > // Draw the sprite< / span >
2010-01-30 06:10:15 +08:00
window.Draw(sprite);
2009-01-29 00:18:34 +08:00
< span style = "color:#008000" > // Draw the string< / span >
2010-01-30 06:10:15 +08:00
window.Draw(text);
2009-01-29 00:18:34 +08:00
< span style = "color:#008000" > // Update the window< / span >
2010-01-30 06:10:15 +08:00
window.Display();
2009-01-29 00:18:34 +08:00
}
}
}
}
< / pre >