Results 1 to 1 of 1

Thread: Resizing the image in picture box

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2022
    Posts
    4

    Resizing the image in picture box

    Hi Everyone!
    I'm doing a program for our final project, It was a game referenced to Flappy Bird, but I called it Flappy Santa because our theme was holidays. VB6 was the only tool we're allowed to used. The problem is that I used a picture box and found some codes here to resize the image but when I run it, some of the pipes were just half pic and the Santa has a black background. What should I do? Please help me. I will attach the picture and the code

    Name:  2022-01-18 (1).jpg
Views: 109
Size:  33.9 KB


    Code:
    Dim santaSpeed As Single
    Dim acceleration As Single
    Dim obstacleSpeed As Single
    Dim Collision As Boolean
    Dim Gap As Integer
    Dim score As Integer
    
    
    Private Sub cmdRestart_Click()
       Form_Load
    End Sub
    
    Private Sub Command1_Click()
    Form25.Show
    Unload Me
    End Sub
    
    Private Sub Form_Click()
        santaSpeed = -120
    
    End Sub
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        santaSpeed = -120
    End Sub
    
    Private Sub Form_Load()
    
        picSanta.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\santa.gif")
        picSanta.ScaleMode = 3
        picSanta.AutoRedraw = True
        picSanta.PaintPicture picSanta.Picture, _
        0, 0, picSanta.ScaleWidth, picSanta.ScaleHeight, _
        0, 0, picSanta.Picture.Width / 26.46, _
        picSanta.Picture.Height / 26.46
        picSanta.Picture = picSanta.Image
    
        lblObstacle1.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\DOWN1.gif")
        lblObstacle1.ScaleMode = 3
        lblObstacle1.AutoRedraw = True
        lblObstacle1.PaintPicture lblObstacle1.Picture, _
        0, 0, lblObstacle1.ScaleWidth, lblObstacle1.ScaleHeight, _
        0, 0, lblObstacle1.Picture.Width / 26.46, _
        lblObstacle1.Picture.Height / 26.46
        lblObstacle1.Picture = lblObstacle1.Image
        
        lblObstacle1B.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\UP1.gif")
        lblObstacle1B.ScaleMode = 3
        lblObstacle1B.AutoRedraw = True
        lblObstacle1B.PaintPicture lblObstacle1B.Picture, _
        0, 0, lblObstacle1B.ScaleWidth, lblObstacle1B.ScaleHeight, _
        0, 0, lblObstacle1B.Picture.Width / 26.46, _
        lblObstacle1B.Picture.Height / 26.46
        lblObstacle1B.Picture = lblObstacle1B.Image
        
        lblObstacle2.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\DOWN2.gif")
        lblObstacle2.ScaleMode = 3
        lblObstacle2.AutoRedraw = True
        lblObstacle2.PaintPicture lblObstacle2.Picture, _
        0, 0, lblObstacle2.ScaleWidth, lblObstacle2.ScaleHeight, _
        0, 0, lblObstacle2.Picture.Width / 26.46, _
        lblObstacle2.Picture.Height / 26.46
        lblObstacle2.Picture = lblObstacle2.Image
        
        lblObstacle2B.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\UP2.gif")
        lblObstacle2B.ScaleMode = 3
        lblObstacle2B.AutoRedraw = True
        lblObstacle2B.PaintPicture lblObstacle2B.Picture, _
        0, 0, lblObstacle2B.ScaleWidth, lblObstacle2B.ScaleHeight, _
        0, 0, lblObstacle2B.Picture.Width / 26.46, _
        lblObstacle2B.Picture.Height / 26.46
        lblObstacle2B.Picture = lblObstacle2B.Image
        
        lblObstacle3.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\DOWN1.gif")
        lblObstacle3.ScaleMode = 3
        lblObstacle3.AutoRedraw = True
        lblObstacle3.PaintPicture lblObstacle3.Picture, _
        0, 0, lblObstacle3.ScaleWidth, lblObstacle3.ScaleHeight, _
        0, 0, lblObstacle3.Picture.Width / 26.46, _
        lblObstacle3.Picture.Height / 26.46
        lblObstacle3.Picture = lblObstacle3.Image
        
        lblObstacle3B.Picture = LoadPicture("C:\Users\home\OneDrive - Technological University of the Philippines\Desktop\BSEE FILES\FINAL ACT COMPROG\UP1.gif")
        lblObstacle3B.ScaleMode = 3
        lblObstacle3B.AutoRedraw = True
        lblObstacle3B.PaintPicture lblObstacle3B.Picture, _
        0, 0, lblObstacle3B.ScaleWidth, lblObstacle3B.ScaleHeight, _
        0, 0, lblObstacle3B.Picture.Width / 26.46, _
        lblObstacle3B.Picture.Height / 26.46
        lblObstacle3B.Picture = lblObstacle3B.Image
    
    
    
    
    
    
        santaSpeed = 0
        acceleration = 5
        obstacleSpeed = 40
        Collision = False
        Gap = 2000
        score = 0
        Timer1.Enabled = True
        cmdRestart.Enabled = False
        picSanta.Top = Me.ScaleHeight / 2
      
        lblObstacle1.Left = Me.ScaleWidth / 3
        lblObstacle1B.Left = Me.ScaleWidth / 3
        lblObstacle2.Left = 2 * Me.ScaleWidth / 3
        lblObstacle2B.Left = 2 * Me.ScaleWidth / 3
        lblObstacle3.Left = Me.ScaleWidth
        lblObstacle3B.Left = Me.ScaleWidth
         
    End Sub
    
    
    Private Sub Timer1_Timer()
        
        moveObstacles
        
        
        santaSpeed = santaSpeed + acceleration
        picSanta.Top = picSanta.Top + santaSpeed
        checkCollision
        If (Collision = True) Then
            Timer1.Enabled = False
            MsgBox ("Game Over .." & vbCrLf & "Your Score is " & score)
            cmdRestart.Enabled = True
        End If
        
       
    End Sub
    
    
    Private Sub checkCollision()
        If (picSanta.Left >= lblObstacle1.Left - picSanta.Width) Then
        If (picSanta.Left <= lblObstacle1.Left + lblObstacle1.Width) Then
            If (picSanta.Top >= lblObstacle1.Top - picSanta.Height) Then
                Collision = True
            End If
            If (picSanta.Top <= lblObstacle1B.Height) Then
                Collision = True
            End If
        End If
        End If
    
        If (picSanta.Left >= lblObstacle2.Left - picSanta.Width) Then
        If (picSanta.Left <= lblObstacle2.Left + lblObstacle2.Width) Then
            If (picSanta.Top >= lblObstacle2.Top - picSanta.Height) Then
                Collision = True
            End If
            If (picSanta.Top <= lblObstacle2B.Height) Then
                Collision = True
            End If
        End If
        End If
        
        If (picSanta.Left >= lblObstacle3.Left - picSanta.Width) Then
        If (picSanta.Left <= lblObstacle3.Left + lblObstacle3.Width) Then
            If (picSanta.Top >= lblObstacle3.Top - picSanta.Height) Then
                Collision = True
            End If
            If (picSanta.Top <= lblObstacle3B.Height) Then
                Collision = True
            End If
        End If
        End If
     
        If (picSanta.Top > Me.ScaleHeight - picSanta.Height) Then
            Collision = True
        End If
    End Sub
    
    
    Private Sub moveObstacles()
    
        lblObstacle1.Left = lblObstacle1.Left - obstacleSpeed
        lblObstacle1B.Left = lblObstacle1.Left
        If (lblObstacle1.Left <= -lblObstacle1.Width) Then
            lblObstacle1.Left = Me.ScaleWidth
            lblObstacle1.Height = Rnd() * (Me.ScaleHeight - 2000)
            lblObstacle1.Top = Me.ScaleHeight - lblObstacle1.Height
            lblObstacle1B.Height = Me.ScaleHeight - lblObstacle1.Height - Gap
    
            score = score + 1
        End If
        
        lblObstacle2.Left = lblObstacle2.Left - obstacleSpeed
        lblObstacle2B.Left = lblObstacle2.Left
        If (lblObstacle2.Left <= -lblObstacle2.Width) Then
            lblObstacle2.Left = Me.ScaleWidth
            lblObstacle2.Height = Rnd() * (Me.ScaleHeight - 2000)
            lblObstacle2.Top = Me.ScaleHeight - lblObstacle2.Height
            lblObstacle2B.Height = Me.ScaleHeight - lblObstacle2.Height - Gap
            
            score = score + 1
        End If
        
        lblObstacle3.Left = lblObstacle3.Left - obstacleSpeed
        lblObstacle3B.Left = lblObstacle3.Left
        If (lblObstacle3.Left <= -lblObstacle3.Width) Then
            lblObstacle3.Left = Me.ScaleWidth
            lblObstacle3.Height = Rnd() * (Me.ScaleHeight - 2000)
            lblObstacle3.Top = Me.ScaleHeight - lblObstacle3.Height
            lblObstacle3B.Height = Me.ScaleHeight - lblObstacle3.Height - Gap
          
            score = score + 1
        End If
    
        
    End Sub
    Last edited by si_the_geek; Jan 18th, 2022 at 08:41 AM. Reason: fixed issue with code tags

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