|
-
May 29th, 2005, 06:14 PM
#1
I can't keep my balls from flickering
I have made this little bouncing ball app that basically moves a circle shape around the screen from inside a Timer_Tick event. The problem is that the ball "flickers" when it moves. What's the best way to stop that? If you want code, I can post it, just ask
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 29th, 2005, 06:19 PM
#2
Software Eng.
Re: I can't keep my balls from flickering
Is the ball an image or PictureBox?
If so, it might help to actually draw it on to the parent window instead, via PaintPicture or the BitBlt API (so in essence -- using a backbuffer).
-
May 29th, 2005, 06:21 PM
#3
Re: I can't keep my balls from flickering
it is a shape control loaded using
VB Code:
strShapeName = "NewShape" & CStr(i)
Me.Controls.Add "VB.Shape", strShapeName
Set bBall(i).Bouncer = Me.Controls(strShapeName)
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 29th, 2005, 06:44 PM
#4
Software Eng.
Re: I can't keep my balls from flickering
And you're just changing the Left and Top properties in a Timer?
What's the Timer's interval?
Have you tried the Ellipse method (of the Form) instead?
-
May 29th, 2005, 07:02 PM
#5
Re: I can't keep my balls from flickering
 Originally Posted by Megatron
And you're just changing the Left and Top properties in a Timer?
What's the Timer's interval?
Have you tried the Ellipse method (of the Form) instead?
the interval can be shorter than the time required by the code (<15ms) or bigger. I turn off the timer at the beginning of the Tick event the turn it off at the end.
edit: check that, its not the time required by code, its the resolution of the timer
I don't know what the Elliplse method is...can you briefly elaborate?
kevin
Last edited by kebo; May 30th, 2005 at 11:34 AM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 30th, 2005, 11:32 AM
#6
Re: I can't keep my balls from flickering
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
May 30th, 2005, 12:28 PM
#7
Re: I can't keep my balls from flickering
Try setting the forms AutoRedraw property to true but I dont think it will help...
The fact is the shape control isnt designed to be moved a lot because it is slow, your best bet if you want to stop the flickering is too have a look as mentioned above at BitBlt or DirectX for drawing.
Bitblt Link in my sig and also try the Games and GFX forum for links to more guides!
Hope it Helps
-
Dec 19th, 2005, 10:54 PM
#8
Addicted Member
Re: I can't keep my balls from flickering
VB Code:
Imports System.Windows.Forms
Imports System.Drawing
Namespace Utilities
Public Class Win32
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, _
ByVal xSrc As Integer, ByVal ySrc As Integer, _
ByVal dwRop As Integer) As Integer
Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Public Const SRCCOPY As Integer = &HCC0020
End Class
Public Class ControlFunctions
Public Shared Function CreateBitmap(ByVal Control As Control) As Bitmap
If Control.Width > 0 AndAlso Control.Height > 0 Then
Dim gDest As Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer
Dim hWnd As Integer = Control.Handle.ToInt32
CreateBitmap = New Bitmap(Control.Width, Control.Height)
gDest = gDest.FromImage(CreateBitmap)
hdcSrc = Win32.GetWindowDC(hWnd)
hdcDest = gDest.GetHdc
Win32.BitBlt(hdcDest.ToInt32, 0, 0, Control.Width, Control.Height, hdcSrc, 0, 0, Win32.SRCCOPY)
gDest.ReleaseHdc(hdcDest)
Win32.ReleaseDC(hWnd, hdcSrc)
End If
End Function
End Class
Public Class UpdateFlashPreventer
Sub New()
End Sub
Sub New(ByVal controlToUpdate As Control)
_control = controlToUpdate
End Sub
Private _control As Control
Private pic As PictureBox
Public Property Control() As Control
Get
Return _control
End Get
Set(ByVal Value As Control)
_control = Value
End Set
End Property
Private _inUpdate As Boolean
Public ReadOnly Property InUpdate() As Boolean
Get
Return _inUpdate
End Get
End Property
Public Sub BeginUpdate()
If Not _control Is Nothing Then
If Not _control.Parent Is Nothing Then
_inUpdate = True
pic = New PictureBox
pic.Size = _control.Size
pic.Image = ControlFunctions.CreateBitmap(_control)
pic.Location = _control.Location
pic.Anchor = _control.Anchor
pic.Dock = _control.Dock
_control.Parent.Controls.Add(pic)
pic.BringToFront()
pic.Refresh()
End If
End If
End Sub
Public Sub EndUpdate()
If pic Is Nothing AndAlso Not _control Is Nothing Then
If TypeOf _control.Parent.Controls(0) Is PictureBox Then
pic = CType(_control.Parent.Controls(0), PictureBox)
End If
End If
If Not _control Is Nothing AndAlso Not _control.Parent Is Nothing AndAlso Not pic Is Nothing Then
pic.SendToBack()
_control.Parent.Controls.Remove(pic)
pic.Dispose()
pic = Nothing
Me._inUpdate = False
End If
End Sub
End Class
to use, place a panel control (called BallPanel) on your form and set its dockstyle to fill, and add YourBallPictureBox into the
VB Code:
Private Sub TimerTick() handles .....
panel
Dim flickerPreventer As New UpdateFlashPreventer(Me.BallPanel)
flickerPreventer.BeginUpdate()
Me.YourBallPictureBox.left = whateverX
Me.YourBallPictureBox.left = whateverY
flickerPreventer.EndUpdate()
End Sub
-
Dec 19th, 2005, 10:57 PM
#9
Re: I can't keep my balls from flickering
Wrong language PeteD. This is the Classic VB section, not VB.NET.
-
Dec 19th, 2005, 11:07 PM
#10
Re: I can't keep my balls from flickering
VB Code:
Dim dirX As Long
Dim dirY As Long
Dim speed As Long
Dim Xval As Long
Dim Yval As Long
Private Sub Form_Load()
dirX = -1
dirY = 1
speed = 10
Me.ScaleMode = vbPixels
End Sub
Private Sub Timer1_Timer()
Cls
Xval = Xval + (speed) * dirX
Yval = Yval + (speed) * dirY
If Xval < 0 Or Xval > Me.ScaleWidth Then dirX = dirX * -1
If Yval < 0 Or Yval > Me.ScaleHeight Then dirY = dirY * -1
Me.Circle (Xval, Yval), 20
End Sub
This will draw a circle and make it move. Hope it helps
-
Dec 19th, 2005, 11:09 PM
#11
Re: I can't keep my balls from flickering
Andrew, this thread is an old thread. Plus you forgot AutoRedraw = True
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|