4 Replies - 1737 Views - Last Post: 26 May 2011 - 07:24 AM Rate Topic: -----

#1 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Graphic Flicker

Posted 20 May 2011 - 12:47 PM

I have a simple game where you use the mouse to tilt the board and roll a ball into a hole.
When that happens I move a shape down 1000 twips to reveal a portion of a, ahem, revealing picture and it slowly moves back up to cover the image to give a sense of tension. The graphic flickers (actually it is the shape that is flickering since I am moving it up slowly.) whether the autoredraw is on or off. I have the picture on the form rather than in a image or picture box since I want the mouse move from the form. I suspect I would get flicker even if I could use image or picture box. Any suggestions how to minimize the flicker. Maybe making the timer (interval now at 100) to a bigger number might help.


Rem shape1:make a black round shape1 600 x 600
Rem shpBall: make a red round shape 500 x 500
Rem a command: cmdstart
Rem a command: cmdExit
Rem two timers one at 100 interval and two at 1000
Rem labels: lblhelp(5)
Rem and a label: lblElapsed
Rem a shape2 to cover the picture   
Rem use any picture you like that is not bigger than the form size
Rem form size: 7500 height, 14000 wide (could be a lot narrower)

Option Explicit
Dim Xval As Integer
Dim Yval As Integer
Dim Xspeed As Integer
Dim Yspeed As Integer
Const Xmid As Integer = 6250
Const Ymid As Integer = 3500
Dim HoleX As Integer
Dim HoleY As Integer
Dim Miss As Integer
Dim Elapsed As Integer
Dim StartTime As Long

Private Sub cmdstart_Click()
Dim I As Integer
Shape1.Visible = 1
For I = 0 To 5: lblhelp(I).Visible = 0: Next
StartTime = Timer
Timer2.Enabled = 1
Timer1.Enabled = 1
cmdstart.Enabled = 0
End Sub

Private Sub form_load()
Dim I As Integer
Dim J As Integer
Dim X As Integer
Dim Y As Integer
Me.Show
Me.Left = 20000
'Me.AutoRedraw = True
Me.Line (0, 7200)-(12000, 7350), 0, BF
'Me.Line (12000, 0)-(12150, 7350), 0, BF
Randomize Timer
HoleX = 10440
HoleY = 3960
lblhelp(0) = "When the cursor is in this quadrant the ball will want to move up and to the right"
lblhelp(1) = "When the cursor is in this quadrant the ball will want to move up and to the left"
lblhelp(2) = "When the cursor is in this quadrant the ball will want to move down and to the left"
lblhelp(3) = "When the cursor is in this quadrant the ball will want to move down and to the right"
lblhelp(4) = "When the cursor is in this small box the ball will eventually slow to a halt"
lblhelp(5) = "Navigate the ball to the black holes"
End Sub

Private Sub form_mousemove(button As Integer, shift As Integer, X As Single, Y As Single)
If X < 250 Or X > 12000 Then Exit Sub
If Y < 250 Or Y > 7200 Then Exit Sub
Xval = (X - Xmid) / 250
Yval = (Y - Ymid) / 150
If Xval > 50 Then Xval = 50
If Xval > 50 Then Xval = 50
End Sub

Private Sub Timer1_Timer()
'Shape2.Top = Shape2.Top - 2
'If Shape2.Top < 0 Then Shape2.Top = 0
Xspeed = Xspeed + Xval
Yspeed = Yspeed + Yval
If Xspeed > 200 Then Xspeed = 200
If Yspeed > 200 Then Yspeed = 200
If Xspeed < -200 Then Xspeed = -200
If Yspeed < -200 Then Yspeed = -200
With shpBall
    If .Top < 0 Then Yspeed = -Yspeed * 0.75: .Top = 0
    If .Top > 6700 Then Yspeed = -Yspeed * 0.75: .Top = 6700
    If .Left < 0 Then Xspeed = -Xspeed * 0.75: .Left = 0
    If .Left > 11500 Then Xspeed = -Xspeed * 0.75: .Left = 11500
    .Left = .Left + Xspeed
    .Top = .Top + Yspeed
End With
    If Xspeed > 1 Then Xspeed = Xspeed - 1
    If Xspeed < 1 Then Xspeed = Xspeed + 1
    If Yspeed > 1 Then Yspeed = Yspeed - 1
    If Yspeed < 1 Then Yspeed = Yspeed + 1
    If Miss > 0 Then Miss = Miss - 1: Exit Sub
    If shpBall.Top > HoleY - 250 And shpBall.Top < HoleY + 250 _
        And shpBall.Left > HoleX - 250 And shpBall.Left < HoleX + 250 Then
            If Abs(Xspeed) > 125 Then Yspeed = -Yspeed: Miss = 2: Exit Sub
            If Abs(Yspeed) > 125 Then Xspeed = -Xspeed: Miss = 2: Exit Sub
        ShowNextHole
    End If
End Sub

Private Sub Timer2_Timer()
Dim Min As Integer
Dim Sec As Integer
Elapsed = Elapsed + 1
Min = Elapsed / 60
Sec = Elapsed Mod 60
lblElapsed = Format(Min, "00") & ":" & Format(Sec, "00")
End Sub

Private Sub ShowNextHole()
Dim I As Integer
Yspeed = 0
Xspeed = 0
Shape2.Top = Shape2.Top + 1000
shpBall.Left = HoleX + 50
shpBall.Top = HoleY + 50
If Shape2.Top > 7000 Then Win: Exit Sub
HoleX = Rnd * 10000
HoleY = Rnd * 6200
Shape1.Left = HoleX
Shape1.Top = HoleY
Shape1.Visible = 1
End Sub

Private Sub Win()
Timer2.Enabled = 0
Timer1.Enabled = 0
lblhelp(5) = "You got it in: " & lblElapsed
lblhelp(5).Visible = 1
End Sub

Private Sub cmdExit_Click()
Unload frmBoard
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Graphic Flicker

#2 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Graphic Flicker

Posted 20 May 2011 - 07:53 PM

may be this link will help you
Was This Post Helpful? 0
  • +
  • -

#3 chuckjessup  Icon User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Graphic Flicker

Posted 22 May 2011 - 05:05 PM

If what Thava has put dosent help I have a post with MS API calls to smoothly redraw the form, it has worked very well for me, it may help you too.
My post HERE


Jesse Fender

This post has been edited by chuckjessup: 22 May 2011 - 05:06 PM

Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Graphic Flicker

Posted 25 May 2011 - 10:25 AM

You can also look into the LockWindowUpdate API function, which is simple to use but probably won't perform as well as Jesse's solution.
Was This Post Helpful? 0
  • +
  • -

#5 Rhymer  Icon User is offline

  • D.I.C Regular

Reputation: 23
  • View blog
  • Posts: 282
  • Joined: 21-April 09

Re: Graphic Flicker

Posted 26 May 2011 - 07:24 AM

Thanks for the suggestions and links. I will try using a picturebox off the playing area and change its height.

Edit:
Yes, that worked fine.
Thanks again.

This post has been edited by Rhymer: 26 May 2011 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1