GDI+ Flimmern bei Ping Pong

  • VB.NET

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    GDI+ Flimmern bei Ping Pong

    Hallo,

    ich habe versucht ein Ping Pong Spiel mit GDI zu machen, nur mal so zur Übung. Aber irgendwie flimmert es die ganze Zeit wenn ich Invaladite benutze und woanders zeichne. Auch

    VB.NET-Quellcode

    1. MyBase.SetStyle
    hat nichts gebracht. Arbeite mit dem Paint-Event. Anbei der bisherige Code.

    Danke im Vorraus TGenius.

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Drawing.Drawing2D
    2. Public Class Form1
    3. Dim bmp As New Bitmap(My.Resources.background)
    4. Dim cpu As Integer = 10
    5. Private Sub RectangleShape1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles p1.Paint
    6. With e.Graphics
    7. .FillRectangle(New LinearGradientBrush(New Rectangle(p1.Left, p1.Top, p1.Width + 1, p1.Height + 1), Color.Yellow, Color.Orange,LinearGradientMode.Horizontal), New Rectangle(p1.Left, p1.Top, p1.Width + 1, p1.Height + 1))
    8. End With
    9. End Sub
    10. Private Sub p2_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles p2.Paint
    11. With e.Graphics
    12. .FillRectangle(New LinearGradientBrush(New Rectangle(p2.Left,p2.Top,p2.Width+2,p2.Height+2),Color.Blue,Color.Aqua,LinearGradientMode.Horizontal),New Rectangle(p2.Left, p2.Top, p2.Width + 2,p2.Height+2))
    13. End With
    14. End Sub
    15. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    16. Me.MaximumSize = Me.Size
    17. Me.MinimumSize = Me.Size
    18. MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    19. End Sub
    20. Private Sub Panel1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    21. Panel1.BackgroundImage = bmp
    22. End Sub
    23. Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    24. Timer1.Start()
    25. End Sub
    26. Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
    27. If ball.Top < p2.Top Then
    28. p2.Top -= cpu
    29. p2.Invalidate()
    30. End If
    31. If ball.Bottom > p2.Bottom Then
    32. p2.Top += cpu
    33. p2.Invalidate()
    34. End If
    35. If MousePosition.Y > p2.Location.Y Then
    36. p1.Top += 5
    37. p1.Invalidate()
    38. End If
    39. If MousePosition.Y < p2.Location.Y Then
    40. p1.Top -= 5
    41. p1.Invalidate()
    42. End If
    43. If p1.Top < 1 Then
    44. p1.Top = 1
    45. End If
    46. If p1.Bottom > Panel1.Height - 1 Then
    47. p1.Top = Panel1.Height - 1 - p1.Height
    48. End If
    49. End Sub
    50. End Class

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

    Probier mal, dem Invalidate als Parameter die Position, an der sich was geändert hat, mitzugeben.
    Dann wird nur noch dieser Ausschnitt refreshed.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    VB.NET-Quellcode

    1. Public Class MyUltraSuperGigaGDIPlusDrawingPanel
    2. Inherits System.Windows.Forms.Panel
    3. Sub New()
    4. MyBase.New()
    5. Me.SetStyle(stylesDieBlazeGeschriebenHat,True)
    6. End Sub
    7. End Class

    erstellen->aus Toolbox einfügen->Paint Event von dem neuen Control verwenden fertig
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---