Results 1 to 3 of 3

Thread: Fill surface with 32x32 tiles?? (DirectX)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421

    Unhappy Fill surface with 32x32 tiles?? (DirectX)

    How can I draw a bunch of 32x32 images onto one single surface? Also, how do I put a surface into a PictureBox? I'm trying to make a map editor but I've been stuck on this for about 2 days now. All I need to know how to do is fill the entire map (which is 255x255 tiles or 8160x8160 pixels) with tiles. I know that all of the map won't be visible at the same time, but that's just how big it is. Please don't point me to that DirectX7 in VB4 site, I've been there but his program runs in full screen mode and mine is in windowed. Please help! Thanks.
    Last edited by Oafo; Jan 6th, 2002 at 08:43 PM.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  2. #2
    Lively Member
    Join Date
    Aug 1999
    Posts
    89
    Hi
    If what you mean is take like several bitmap files and draw them onto one screen, the best way to do that would be to place them all in 1 bitmap before hand to simplify things, like if you have a picture of a guy walking, you would store all the frames of him walking in one bitmap file.

    Code:
      Dim dx As New DirectX7
      Dim lpDD As DirectDraw7
      Dim ddsPrimarySurface As DirectDrawSurface7
      Dim ddsSurface As DirectDrawSurface7
      Dim ddsd As DDSURFACEDESC2
      Dim ddClip As DirectDrawClipper
    
        ' create directdraw 
        Set lpDD = dx.DirectDrawCreate("")
        ' setting to window mode
        Call lpDD.SetCooperativeLevel(frmMain.hWnd, DDSCL_NORMAL)
        ddsd.lFlags = DDSD_CAPS
        ddsd.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
        ' create primary surface where you will blt to
        Set ddsPrimarySurface = lpDD.CreateSurface(ddsd)
        ' now set up DirectDrawSurfaceDescription for a surface we will load the bitmap into
        ddsd.lFlags = DDSD_CAPS
        ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
        ddsd.lFlags = DDSD_HEIGHT Or DDSD_WIDTH
        Set ddsSurface = lpDD.CreateSurfaceFromFile(BITMAP FILE, ddsd)
       ' now set a clipper so we stay within the picturebox
        Set ddClip = lpDD.CreateClipper(0)
       ' this is how you get it to blt in a picture box
        ddClip.SetHWnd picture1.hWnd
        ddsPrimarySurface.SetClipper ddClip
    now after you have set up directx you can blit it into a picture box by
    Code:
      call ddsPrimarySurface.blt(DestRect, ddsSurface, SourceRect, DDBLT_WAIT)
    then to be able to scroll the map and draw all the tiles
    if you've gone through and done an MapArray(# of X tiles, # of Y tiles) and filled each spot with what type of tile you want blitted there, you can make something like
    Code:
    yy = 0
    xx = 0
    ' the DestRect will be where its suppose to be placed, according to the OffSets, since we have a clipper, we'll just start blitting at whatever values the offsets are at
    ' so
    DestRect.top = YOffset 
    DestRect.left = XOffset
      for x = CurrentXSpot to CurrentXSpot + 
    HowManyTilesCanBeDisplayedHorizontally, NOTE you'll need to check and make sure it doesn't exceed the # of X tiels
       yy = 0
        for y = CurrentYSpot to CurrentYSpot + TilesVertically
           ' then just blit it here
           ' tricker part, where you'll need to figure how many pixels over you need to adjust, see below FIRST
            ' SourceRect, should be the rectangle you want to blt, say the guy
            DestRect.top = DestRect.top + TILE_HEIGHT
            DestRect.left = DestRect.left + TILE_WIDTH
            DestRect.right = DestRect.left + TILE_WIDTH
            DestRect.bottom = DestRect.top + TILE_HEIGHT
            ' Source Rect would be what tile you wanted blitted at the cordinates
            call ddsPrimarySurface.blt(DestRect, ddsSurface, SourceRect(CurrentXSpot, CurrentYSpot), DDBLT_WAIT)
        yy = yy + 1
        next y
        xx = xx + 1
    next x
    to make an offset
    everytime say you press the right arrow key, you can have the XOffSet move 1 pixel, so you need a variable
    Code:
    ' these should be globals for your form
    dim XOffSet as integer, YOffSet as integer
    
    so to move the pixel over everytime you press right arrow key
    XOffSet = XOffSet - 1 ' to move right
    ' you'll need to see if XOffSet equals a whole tile
    if XOffSet = -TILE_WIDTH then ' when moving right
      XOffSet = 0
      CurrentXSpot = CurrentXSpot + 1 ' so we moved over a bit
    end if
    ' thats just to move right, but you get the idea, and you should be able to figure out the rest going left, up and down
    ' also you would want to make sure they don't keep going past the boundaries of the map
    Hope that helps you

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Thanx Allanon, I'll try that out.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

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