Results 1 to 8 of 8

Thread: Why do the pictures keep blinking??

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Question Why do the pictures keep blinking??

    To Members, recently I been creating a enhanced version of Snake, a game also on mobile phones. I find many bugs that are hard to pluck out but I have most trouble with one. In my game the head of the snake(image control) and the bug(also image control) keep on blinking endlessly while a timer is enabled controling each and every move of the snake. I have tried everything I could and need help. Does anyone have any advice.

    Nathan...
    Last edited by n_tarr; Jul 6th, 2002 at 02:41 AM.

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I think that's the problem with image controls. If you want to do it without the blinking you'll have to "paint" the snake directly to a picture box (with AutoRedraw set to true) using either BitBlt (API) or PaintPicture.

  3. #3
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    actually that happened to me too... i fixed it with some help though i cant remember where from (probably this site) well anyways you did one of two things, 1. You used different graphics programs to make the images(if there is any transperency scrap that for the real color), 2. Your graphics program sucks( dont use animagic or paint those two dont seem to work for moving images...)

  4. #4
    Junior Member
    Join Date
    Jul 2002
    Location
    Montreal, Québec
    Posts
    20
    Actually, the program used to create an image doesn't change a thing. A bitmap is still a bitmap.

    The problem might be that you're updating the screen too often or too little often. For example, you're redrawing before the screen can finish refreshing ("vblank") or too late after it has refreshed. I'm not sure what the problem is exactly. You should post the faulty code here, that would help an awful lot.

  5. #5
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    i'd have to agree with rick. when using controls it is going to blink. I suggest learning bitblt API, it should be relatively easy to convert your code to the bitblt() version.

  6. #6
    Lively Member FireSlash518's Avatar
    Join Date
    Nov 2001
    Posts
    67
    well, there are 2 ways i know to stop it.

    the way i fixed it was by setting the snake head to visible=false before setting locations, then making it visible again when i was done changing it, however i made sure only to do that when i was moving it. it still kinda flickered though.

    the best way would be to create a second form, and use bitblt to copy the entire form to a display form. now, this would likly take some code slicing since i bet your input is forum_keypress based, but its workable.

    Leader of the Maxoverkill Mods
    -Fire§lash

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Thanks but still having problems

    Thanks again. I see how you can use BitBlt or Paint Picture but how do I remove the BitBlt picture because when the snake moves over it leaves the sides of that picture (which is the bug) there and i keep on getting dots everywhere on my form. My snake is is made from the line function.

    For the moment I have decided to make the bug an picture control with auto-redraw true and backcolor equal to form's back color. One more question. How do you get the line control to go through one side of the form and appear at the other side going at the same direction? Here is the source code:

    'This sub procedure draws the snake in it's direction.
    Sub SnakeMotion(ByVal Motion As Byte)
    Dim i As Integer
    'These invisible lines control the length of the
    'snake hiding the trail of the snake.
    picBack.Line (XPos(1), YPos(1))-(XPos(2), YPos(2)), picBack.BackColor
    picBack.Line (XPos(1) - 1, YPos(1) - 1)-(XPos(2) - 1, YPos(2) - 1), picBack.BackColor
    picBack.Line (XPos(1) + 1, YPos(1) + 1)-(XPos(2) + 1, YPos(2) + 1), picBack.BackColor
    'This overlaps the dots
    For i = 1 To Length - 1
    XPos(i) = XPos(i + 1)
    YPos(i) = YPos(i + 1)
    Next i
    'This checks the moves of the snake depending on
    'the motion and inverted setting.
    If Inverted = False Then
    Select Case Motion
    Case DUp
    'This tells the program to move the snake this way.
    YPos(Length) = YPos(Length - 1) - 10
    'This tells which head is needed for the direction.
    imgHead.Picture = headUp.Picture
    'This sets the picture and position for the snake's
    'tongue in it's direction and visibility for bug.
    imgTongue.Picture = tongueu.Picture
    imgTongue.Left = XPos(i) - (imgTongue.Width / 2)
    imgTongue.Top = YPos(i) - (imgTongue.Height / 2) - 10
    'This sets the picture and position for the snake's
    'tongue in it's direction and visibility for apple.
    imgTongue2.Picture = tongueu.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2)
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2) - 10
    Case DDown
    YPos(Length) = YPos(Length - 1) + 10
    imgHead.Picture = headDown.Picture
    imgTongue.Picture = tongued.Picture
    imgTongue.Left = XPos(i) - (imgTongue.Width / 2)
    imgTongue.Top = YPos(i) - (imgTongue.Height / 2) + 10
    imgTongue2.Picture = tongued.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2)
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2) + 10
    Case DLeft
    XPos(Length) = XPos(Length - 1) - 10
    imgHead.Picture = headLeft.Picture
    imgTongue.Picture = tougnel.Picture
    imgTongue.Left = XPos(i) - (imgTongue.Width / 2) - 10
    imgTongue.Top = YPos(i) - (imgTongue.Height / 2)
    imgTongue2.Picture = tougnel.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2) - 10
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2)
    Case DRight
    XPos(Length) = XPos(Length - 1) + 10
    imgHead.Picture = headRight.Picture
    imgTongue.Picture = tonguer.Picture
    imgTongue.Left = XPos(i) - (imgTongue.Width / 2) + 10
    imgTongue.Top = YPos(i) - (imgTongue.Height / 2)
    imgTongue2.Picture = tonguer.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2) + 10
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2)
    End Select

    Else

    Select Case Motion
    Case DUp
    Direction = DUp
    YPos(Length) = YPos(Length - 1) + 10
    imgHead.Picture = headDown.Picture
    imgTongue.Picture = tongued.Picture
    imgTongue.Left = XPos(i) - (imgTongue.Width / 2)
    imgTongue.Top = YPos(i) - (imgTongue.Height / 2) + 10
    imgTongue2.Picture = tongued.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2)
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2) + 10
    Case DDown
    Direction = DDown
    YPos(Length) = YPos(Length - 1) - 10
    imgHead.Picture = headUp.Picture
    imgTongue.Picture = tongueu.Picture
    imgTongue.Left = XPos(i) - (imgTongue.Width / 2)
    imgTongue.Top = YPos(i) - (imgTongue.Height / 2) - 10
    imgTongue2.Picture = tongueu.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2)
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2) - 10
    Case DLeft
    Direction = DLeft
    XPos(Length) = XPos(Length - 1) + 10
    imgHead.Picture = headRight.Picture
    imgTongue.Picture = tonguer.Picture
    imgTongue.Left = XPos(i) - (imgTongue2.Width / 2) + 10
    imgTongue.Top = YPos(i) - (imgTongue2.Height / 2)
    imgTongue2.Picture = tonguer.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2) + 10
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2)
    Case DRight
    Direction = DRight
    XPos(Length) = XPos(Length - 1) - 10
    imgHead.Picture = headLeft.Picture
    imgTongue.Picture = tougnel.Picture
    imgTongue.Left = XPos(i) - (imgTongue2.Width / 2) - 10
    imgTongue.Top = YPos(i) - (imgTongue2.Height / 2)
    imgTongue2.Picture = tougnel.Picture
    imgTongue2.Left = XPos(i) - (imgTongue2.Width / 2) - 10
    imgTongue2.Top = YPos(i) - (imgTongue2.Height / 2)
    End Select
    End If
    'Draws the visible body of the snake in position
    ', movement and color.
    For i = 1 To Length - 1
    picBack.Line (XPos(i), YPos(i))-(XPos(i + 1), YPos(i + 1)), SnakeColor
    picBack.Line (XPos(i) - 1, YPos(i) - 1)-(XPos(i) - 1, YPos(i) - 1), vbBlack
    picBack.Line (XPos(i), YPos(i))-(XPos(i), YPos(i)), vbBlack
    Next i
    'Sets the position of the snake head
    imgHead.Left = XPos(i) - (imgHead.Width / 2)
    imgHead.Top = YPos(i) - (imgHead.Height / 2)
    'Gives the snake a sense of smell for apples and
    'bugs and sticks out the tongue.
    If Abs(imgHead.Left - x) < 25 And Abs(imgHead.Top - y) < 25 And imgBug.Visible = True Then
    imgTongue.Visible = True
    Else
    imgTongue.Visible = False
    End If
    If Abs(imgHead.Left - X2) < 25 And Abs(imgHead.Top - Y2) < 25 And imgApple.Visible = True Then
    imgTongue2.Visible = True
    Else
    imgTongue2.Visible = False
    End If
    'Monitors the snake for collision, or the eating
    ' of the bug/apple.
    CrashMonitor
    EatBug
    EatApple
    'If crashed then do the following.
    If CrashMonitor = True Then MsgBox "You Crashed", vbExclamation: Call CheckScore(Score): Score = 0: lblScore.Caption = "Score: " & Score: Call NewGame: Exit Sub
    'Draws the grid and sets the line settings.
    DrawGrid
    picBack.DrawStyle = 0
    picBack.DrawWidth = 8
    End Sub

    'Re/creates the body of the snake.
    Sub SetSnake()
    Dim i As Integer
    'reset snake position
    ReDim XPos(1 To 10) As Integer
    ReDim YPos(1 To 10) As Integer
    ''clear the form of it's previous line drawings.
    ' picBack.Cls
    'Set Direction according to inverted setting.
    If mnuInvert.Checked = False Then
    Direction = DRight
    Else
    Direction = DLeft
    End If
    'reset length for snake to 10.
    Length = 10
    're/create body for snake.
    For i = 1 To Length
    XPos(i) = (10 * i)
    YPos(i) = 10
    Next i
    'set background color.
    picBack.BackColor = BackClr
    'create line and overlap dots.
    For i = 1 To 9
    picBack.Line (XPos(i), YPos(i))-(XPos(i + 1), YPos(i + 1)), SnakeColor
    picBack.Line (XPos(i), YPos(i))-(XPos(i), YPos(i)), vbBlack
    picBack.Line (XPos(i) - 1, YPos(i) - 1)-(XPos(i) - 1, YPos(i) - 1), vbBlack
    Next i
    'set the head of the snake to it's position
    imgHead.Left = XPos(i) - (imgHead.Width / 2)
    imgHead.Top = YPos(i) - (imgHead.Height / 2)
    'set the tongue and head picture to right direction.
    'set the tongue of the snake to it's position (bug)
    imgTongue.Visible = False
    imgTongue.Picture = tonguer
    'set the tongue of the snake to it's position (apple)
    imgTongue2.Visible = False
    imgTongue2.Picture = tonguer
    imgHead.Picture = headRight.Picture
    End Sub

    I hope you can help me (sorry about the length of the code).

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    10

    Exclamation Not sure, need help now!!

    Im still not sure. How do you really use bitblt to make an bitmap's background transparent, when you have 4 imgaes to bitblt it to at different times when a key is pressed(the image is the default image of the snake's head, while the other four images are snake head's going four directions, left, right, up and down)

    Everything else is working fine, nothing else will blink except if you change the snake's head image to an gif transparent image. But this was changed to a bitmap and picture control and it does not blink. I need help now, my game will be presented tommorow
    (14/8/02) and this is the only time i will get. Your help will be appreciated( sorry about the spelling mistakes if any, im in a hurry!!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width