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...
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).
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!!) :(