SFML: einfache 2D GrafikEngine

  • VB.NET

Es gibt 40 Antworten in diesem Thema. Der letzte Beitrag () ist von Artentus.

    SFML: einfache 2D GrafikEngine

    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^^



    VB.NET-Quellcode

    1. Imports SFML
    2. Public Class Form1
    3. Public WithEvents RenderWindow As Graphics.RenderWindow
    4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5. End Sub
    6. Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
    7. Me.Hide()
    8. RunRenderEngine()
    9. End Sub
    10. Dim Sprite As Graphics.Sprite
    11. Sub RunRenderEngine()
    12. 'Unser RenderWindow wird mit einer Zeile erstellt und ist dann einsatzbereit
    13. RenderWindow = New Graphics.RenderWindow(New Window.VideoMode(800, 600), "SFML TEST")
    14. 'Hier können einige Einstellungen vorgenommen werden
    15. With RenderWindow
    16. '.SetFramerateLimit(120) 'Framerate auf 120 FPS begrenzen
    17. '.UseVerticalSync(True) 'Verticale Sync - geringere Framerate!
    18. .ShowMouseCursor(False) 'lässt den mouseCursor verschwinden
    19. End With
    20. 'Grafiken etc werden geladen
    21. Sprite = New Graphics.Sprite(New Graphics.Image("C:\Bild.bmp"))
    22. 'Der RenderLoop..
    23. Do While RenderWindow.IsOpened
    24. 'Die Zeile lässt die Events ausführen (z.b. Tastatureingaben etc)
    25. RenderWindow.DispatchEvents()
    26. 'ZEICHENOPERATIONEN:
    27. 'färbt den Bildschirm schwarz
    28. RenderWindow.Clear(New Graphics.Color(0, 0, 0))
    29. 'zeichnet ein sprite auf den bildshcrim
    30. RenderWindow.Draw(Sprite)
    31. 'Zeichnet die FPS zahl auf den Bildschrim
    32. RenderWindow.Draw(New Graphics.String2D("FPS: " & (Math.Round(1 / RenderWindow.GetFrameTime).ToString)))
    33. 'Aktualisiert den Bildschirm
    34. RenderWindow.Display()
    35. 'verhindert ein "einfrieren" der GUI. Man könnte den Renderloop sicherlich auch in einem Thread auslagern..
    36. Application.DoEvents()
    37. Loop
    38. End Sub
    39. Private Sub RenderWindow_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles RenderWindow.Closed
    40. RenderWindow.Close()
    41. Me.Close()
    42. End Sub
    43. Private Sub RenderWindow_KeyPressed(ByVal sender As Object, ByVal e As SFML.Window.KeyEventArgs) Handles RenderWindow.KeyPressed
    44. 'einige tasten funsen nciht - ESC, PFeiltasten ..
    45. 'hier kann die position des sprite mittels WASD verändert werden
    46. Dim _x As Single = Sprite.Position.X
    47. Dim _y As Single = Sprite.Position.Y
    48. If e.Code = Window.KeyCode.W Then _y -= 10
    49. If e.Code = Window.KeyCode.S Then _y += 10
    50. If e.Code = Window.KeyCode.A Then _x -= 10
    51. If e.Code = Window.KeyCode.D Then _x += 10
    52. Sprite.Position = New Graphics.Vector2(_x, _y)
    53. End Sub
    54. End Class


    EDIT: Man beachte, dass die Datei "C:\Bild.bmp" existieren muss!

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „FreakJNS“ ()

    If you follow @sourceforge on Twitter, you may have seen some tweets last week from certain users outside the US complaining that they no longer had access to SourceForge.net. Here’s why.

    Since 2003, the SourceForge.net Terms and Conditions of Use have prohibited certain persons from receiving services pursuant to U.S. laws, including, without limitations, the Denied Persons List and the Entity List, and other lists issued by the U.S. Department of Commerce, Bureau of Industry and Security. The specific list of sanctions that affect our users concern the transfer and export of certain technology to foreign persons and governments on the sanctions list. This means users residing in countries on the United States Office of Foreign Assets Control (OFAC) sanction list, including Cuba, Iran, North Korea, Sudan, and Syria, may not post content to, or access content available through, SourceForge.net. Last week, SourceForge.net began automatic blocking of certain IP addresses to enforce those conditions of use.

    As one of the first companies to promote the adoption and distribution of free and open source software, and one that still puts open source at the center of its corporate ideals, restrictions on the free flow of information rub us the wrong way. However, in addition to participating in the open source community, we also live in the real world, and are governed by the laws of the country in which we are located. Our need to follow those laws supersedes any wishes we might have to make our community as inclusive as possible. The possible penalties for violating these restrictions include fines and imprisonment. Other hosting companies based in the US have similar legal and technical restrictions in place.

    We regret deeply that these sanctions may impact individuals who have no malicious intent along with those whom the rules are designed to punish. However, until either the designated governments alter the practices that got them on the sanctions list, or the US government’s policies change, the situation must remain as it is.
    learn2proxy
    Alle Proxies können nicht gesperrt sein. Komm nicht mit "Ist aber so mimimi", sondern setz dich hin und such nach welchen.
    Dass die Mullus in der Regierung die offensichtlichen Proxies auf den ersten 5 Google-Seiten gesperrt haben, ist klar. Was machst du überhaupt im Iran?
    Sie ist mit Sicherheit schneller als GDI

    Irgendwie logisch, guck dir den Aufbau an, das ist genau gleich wie bei DirectX oder OpenGL, deshalb liegt sehr sehr nahe, dass es auf diese Systeme aufbaut, welche ebenso viel und mehr unterstützen...
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---
    hast du schon gg24.de probiert ?
    der geht zumisnestens in der schule XD
    mfg blacknetworkbit
    MFG 0x426c61636b4e6574776f726b426974
    InOffical VB-Paradise IRC-Server
    webchat.freenode.net/
    Channel : ##vbparadise