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 hat nichts gebracht. Arbeite mit dem Paint-Event. Anbei der bisherige Code.
Danke im Vorraus TGenius.
Spoiler anzeigen
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 hat nichts gebracht. Arbeite mit dem Paint-Event. Anbei der bisherige Code.
Danke im Vorraus TGenius.
VB.NET-Quellcode
- Imports System.Drawing.Drawing2D
- Public Class Form1
- Dim bmp As New Bitmap(My.Resources.background)
- Dim cpu As Integer = 10
- Private Sub RectangleShape1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles p1.Paint
- With e.Graphics
- .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))
- End With
- End Sub
- Private Sub p2_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles p2.Paint
- With e.Graphics
- .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))
- End With
- End Sub
- Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- Me.MaximumSize = Me.Size
- Me.MinimumSize = Me.Size
- MyBase.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
- End Sub
- Private Sub Panel1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
- Panel1.BackgroundImage = bmp
- End Sub
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- Timer1.Start()
- End Sub
- Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
- If ball.Top < p2.Top Then
- p2.Top -= cpu
- p2.Invalidate()
- End If
- If ball.Bottom > p2.Bottom Then
- p2.Top += cpu
- p2.Invalidate()
- End If
- If MousePosition.Y > p2.Location.Y Then
- p1.Top += 5
- p1.Invalidate()
- End If
- If MousePosition.Y < p2.Location.Y Then
- p1.Top -= 5
- p1.Invalidate()
- End If
- If p1.Top < 1 Then
- p1.Top = 1
- End If
- If p1.Bottom > Panel1.Height - 1 Then
- p1.Top = Panel1.Height - 1 - p1.Height
- End If
- End Sub
- End Class
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „TGenius“ ()