Tile Map in visual basic

Posted on 2003-03-15
Medium Priority
Last Modified: 2008-02-01
I am confused with an answer I recieved I am trying to just get an example of a Window Moded VB map that I can scroll around and it still be decent.  I tried example below but cant get it to draw right it ends up drawing part of the form and willl not let me scroll to left and will not draw into map picture box only the back buffer one.

Three PictureBoxes.

The Picture Boxes are all set to scalemode vbPixel.
The Backbuffer and Source are set to AutoRedraw.
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByBal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC as Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Public Sub RefreshMap()
  'picSrc = Invisible Picture Box containing whole map
  'picBack = Invisible Picture Box for back buffer and work.
  'picDest = Picture Box for displaying to user.

  Dim picSrc As PictureBox
  Dim picBack As PictureBox
  Dim picDest As PictureBox

  Dim StartX As Long
  Dim StartY As Long

  Set picSrc = MainForm.pbSource
  Set picBack = MainForm.pbBack
  Set picDest = MainForm.pbMap

  StartX = -MainForm.HScrollMap.Value
  StartY = -MainForm.VScrollMap.Value

  BitBlt picBack.hDC, 0, 0, _
       picBack.ScaleWidth, picDest.ScaleHeight, _
       picSrc.hDC, StartX, StartY, vbSrcCopy

  'Do other things to picBack here like draw
  'on map text messages, sprites, etc.

  BitBlt picDest.hDC, 0, 0, _
       picDest.ScaleHeight, picDest.ScaleWidth, _
       picDest.hDC, 0, 0, vbSrcCopy

End Sub

Question by:Hook333
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Hermetic earned 400 total points
ID: 8148810
You have to set Min and Max of the scrollbars and refresh the picture boxes. like this:
(btw - The last bitblt has the width and height switched. and the second hDC should be of picBack.)

Private Sub Form_Load()
    HScrollMap.Min = 0
    VScrollMap.Min = 0
    HScrollMap.Max = pbSrc.ScaleWidth
    VScrollMap.Max = pbSrc.ScaleHeight
    HScrollMap.SmallChange = 5
    VScrollMap.SmallChange = 5
    HScrollMap.LargeChange = 50
    VScrollMap.LargeChange = 50
End Sub

Private Sub HScrollMap_Change()
End Sub

Private Sub HScrollMap_Scroll()
End Sub

Private Sub VScrollMap_Change()
End Sub

Private Sub VScrollMap_Scroll()
End Sub

Expert Comment

ID: 8148826
Just to be clear, the last BitBlt should be:

BitBlt picDest.hDC, 0, 0, _
      picDest.ScaleWidth, picDest.ScaleHeight, _
      picBack.hDC, 0, 0, vbSrcCopy

For the Scroll mins and maxs in my example, you either have to make them negative, or remove the minus sign in the RefreshMap function


Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question