Guten Tag. Ich bin heute auf "Gold gestoßen"! Ich habe eine kleine aber sehr einfach zu handhabende 2D Grafik Engine gefunden. Sie ist mit Sicherheit schneller als GDI und unterstützt außerdem Audio und Multiplayer Programmierung (habe ich mir bisher nicht angesehen, lediglich das 2D zeichnen). Das ganze kommt zwar an kein crysis ran, aber für ein einfaches RPG sollte es dicke reichen (bei fullscreenauflösung von 1980x1050 macht das ding in meinem beispielproject immerhin 600+ FPS, bei 800x600 (sollte für ein RPG ja reichen) locker über 2000).
Hier ein kleines TUT wie man die "Simple and Fast Multimedia Libary" zum laufen bekommt:
einfach auf der SFML-Homepage unter Downloads das "SFML.Net development files (libraries / external libraries)" herunterladen, entpacken, den inhalt vom lib und extlibs-Ordner in den Debugordner eines Visual Studio Projects kopieren (funktioniert auch mit Konsolenanwendungen! das "RenderWindow" wird von der Lib erzeugt). Nun einfach die 3 DLLs (sflmlnet-*.dll) als verweis hinzufügen und los gehts^^
EDIT: Man beachte, dass die Datei "C:\Bild.bmp" existieren muss!
Hier ein kleines TUT wie man die "Simple and Fast Multimedia Libary" zum laufen bekommt:
einfach auf der SFML-Homepage unter Downloads das "SFML.Net development files (libraries / external libraries)" herunterladen, entpacken, den inhalt vom lib und extlibs-Ordner in den Debugordner eines Visual Studio Projects kopieren (funktioniert auch mit Konsolenanwendungen! das "RenderWindow" wird von der Lib erzeugt). Nun einfach die 3 DLLs (sflmlnet-*.dll) als verweis hinzufügen und los gehts^^
VB.NET-Quellcode
- Imports SFML
- Public Class Form1
- Public WithEvents RenderWindow As Graphics.RenderWindow
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
- Me.Hide()
- RunRenderEngine()
- End Sub
- Dim Sprite As Graphics.Sprite
- Sub RunRenderEngine()
- 'Unser RenderWindow wird mit einer Zeile erstellt und ist dann einsatzbereit
- RenderWindow = New Graphics.RenderWindow(New Window.VideoMode(800, 600), "SFML TEST")
- 'Hier können einige Einstellungen vorgenommen werden
- With RenderWindow
- '.SetFramerateLimit(120) 'Framerate auf 120 FPS begrenzen
- '.UseVerticalSync(True) 'Verticale Sync - geringere Framerate!
- .ShowMouseCursor(False) 'lässt den mouseCursor verschwinden
- End With
- 'Grafiken etc werden geladen
- Sprite = New Graphics.Sprite(New Graphics.Image("C:\Bild.bmp"))
- 'Der RenderLoop..
- Do While RenderWindow.IsOpened
- 'Die Zeile lässt die Events ausführen (z.b. Tastatureingaben etc)
- RenderWindow.DispatchEvents()
- 'ZEICHENOPERATIONEN:
- 'färbt den Bildschirm schwarz
- RenderWindow.Clear(New Graphics.Color(0, 0, 0))
- 'zeichnet ein sprite auf den bildshcrim
- RenderWindow.Draw(Sprite)
- 'Zeichnet die FPS zahl auf den Bildschrim
- RenderWindow.Draw(New Graphics.String2D("FPS: " & (Math.Round(1 / RenderWindow.GetFrameTime).ToString)))
- 'Aktualisiert den Bildschirm
- RenderWindow.Display()
- 'verhindert ein "einfrieren" der GUI. Man könnte den Renderloop sicherlich auch in einem Thread auslagern..
- Application.DoEvents()
- Loop
- End Sub
- Private Sub RenderWindow_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles RenderWindow.Closed
- RenderWindow.Close()
- Me.Close()
- End Sub
- Private Sub RenderWindow_KeyPressed(ByVal sender As Object, ByVal e As SFML.Window.KeyEventArgs) Handles RenderWindow.KeyPressed
- 'einige tasten funsen nciht - ESC, PFeiltasten ..
- 'hier kann die position des sprite mittels WASD verändert werden
- Dim _x As Single = Sprite.Position.X
- Dim _y As Single = Sprite.Position.Y
- If e.Code = Window.KeyCode.W Then _y -= 10
- If e.Code = Window.KeyCode.S Then _y += 10
- If e.Code = Window.KeyCode.A Then _x -= 10
- If e.Code = Window.KeyCode.D Then _x += 10
- Sprite.Position = New Graphics.Vector2(_x, _y)
- End Sub
- End Class
EDIT: Man beachte, dass die Datei "C:\Bild.bmp" existieren muss!
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „FreakJNS“ ()