Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt
Map Movement in BitBlt Map Movement in BitBlt
Map Movement in BitBlt
Go Back  Xtreme Visual Basic Talk > > > Map Movement in BitBlt


Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2004, 06:50 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default Grid with BitBlt


I have been to http://fox.acky.net/tiletut/1.1.php

I used the tutorial there, I was wondering if anyone knows if this is good and have done something in this style before?

For the BitBlt I declared,

Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Long, _
ByVal X As Long, ByVal 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 Const SRCCOPY = &HCC0020

I was also wondering if this is a good thing to do in VB .Net?

I did not know how to do the equivalence of hDC (because there is none) in .NET, and I also did not know how to change this,

Code:
                    'Draw tile
                    BitBlt(Camera.FrontDC, _
                        X * TileSize, Y * TileSize, _
                        TileSize, TileSize, _
                        Tile(TileIndex).DC, _
                        0, 0, SRCCOPY)
into a draw function, using GDI+

So that is why i added the BitBlt Function,

Also the grid does not actually appear, and (with breakpoints) I have seen it go through the code correctly, is there an actualy tile grid that should appear?
thanx in advance.

Last edited by theController; 11-28-2004 at 09:05 PM. Reason: I fixed my problem
Reply With Quote
  #2  
Old 11-29-2004, 08:24 AM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

The closest thing that I have seen to a DC (hDC) is a Bitmap object (and a Bitmap object reference or Graphics object). You can draw to and from one.

BitBlt shouldn't really be used in VB.NET unless you really have a reason to do so.

The equivalent to the above line would be something along the lines of:

GFX.DrawImage(Tile(TileIndex), X * TileSize, Y * TileSize, New Rectangle(0, 0, TileSize, TileSize), GraphicsUnit.Pixel) 'Bitblt equivalent.
(which can be simplified into another overloaded due to the 0, 0)
GFX.DrawImage(Tile(TileIndex), X * TileSize, Y * TileSize, TileSize, TileSize)
(and can be simplified to this overload if TileSize is indeed the width of the Tile(TileIndex) picture.
GFX.DrawImage(Tile(TileIndex), X * TileSize, Y * TileSize)

Before any of this will work, things have to be set up.
Tile(TileIndex) would have to be a Bitmap, meaning that
Tile() would have to be an array of Bitmaps.
CameraFront (replacing Camera.FrontDC) would also have to be declared as an Bitmap, but since we're drawing to the CameraFront, we'd need a GFX aimed at the CameraFront, so we'd have
Dim GFX As Graphics = Graphics.FromImage(CameraFront)
And now it should work.

Quote:
I have seen it go through the code correctly, is there an actualy tile grid that should appear?
thanx in advance.
You'd have to put this in a For Loop, put pictures in the Tile(TileIndex) bitmaps, and then show the CameraFront bitmap somewhere after drawing it.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 11-29-2004, 10:25 AM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

for the reset function of the camera, it needs the Camera Front which is dimmed as a bitmap, and when i put it in the brackets, no build errors are present, but it says it cannot be null.

Now I know this is because it hasnt actually set the bitmap to anything, and I know it has to be the screen?

Would I want to make this bitmap my full map? or the viewing area?

I am guessing I would have it draw all of the tiles, and then sort of take a snapshot of this and store it as the bitmap? and make this the Camera Front?

For the code,

Code:
mCamera.Reset(Camera.CameraFront)
Using the module,

Code:
    Public Sub Reset(ByVal iFront As Bitmap)

        With Camera
            'Get viewport size
            .w = iFront.Width
            .h = iFront.Height

            'Calculate number of visible tiles
            .TilesX = (.w / 20)
            .TilesY = (.h / 20)

            'Get device context
            Camera.CameraFront = iFront
        End With

    End Sub

Last edited by theController; 11-29-2004 at 02:56 PM. Reason: I fixed my problem
Reply With Quote
  #4  
Old 11-29-2004, 06:28 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You need to instantiate the bitmap.
Dim CameraFront As Bitmap = New Bitmap(width, height)


What would CameraFront be in the original BitBlt code? It would probably be fine as the form width or whatever the map will be drawn on.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 11-29-2004, 06:37 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

I am now getting an error stating that form 1 is null

Edit by Iceplug: I had to remove 2 EXE(s) from this attachment
Attached Files
File Type: zip MapScrolling.zip (1.40 MB, 16 views)

Last edited by Iceplug; 11-29-2004 at 07:38 PM.
Reply With Quote
  #6  
Old 11-29-2004, 06:42 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

What code are you using? If you are actually coding in Form1, you should put the code in Form_Load or at least after InitializeComponent. If you are using a sub form, you need to put the code in the form or else, use the variable that you are using to create the form. If you are using Application.Run, then you need to create a variable that holds a reference to the new form instead of passing the New form directly to Application.Run() .
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #7  
Old 11-29-2004, 06:43 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

Quote:
Originally Posted by Iceplug
What code are you using? If you are actually coding in Form1, you should put the code in Form_Load or at least after InitializeComponent. If you are using a sub form, you need to put the code in the form or else, use the variable that you are using to create the form. If you are using Application.Run, then you need to create a variable that holds a reference to the new form instead of passing the New form directly to Application.Run() .
Wow that was a quick response , lol I just added my project to the reply, I still cant see why it would do this?
Reply With Quote
  #8  
Old 11-29-2004, 07:33 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

sorry, the other one included a large bitmap...

Edit by Iceplug: I had to remove 2 EXE(s) from this attachment
Attached Files
File Type: zip MapScrolling.zip (22.2 KB, 16 views)

Last edited by Iceplug; 11-29-2004 at 07:41 PM.
Reply With Quote
  #9  
Old 11-29-2004, 07:55 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

OK, first of all, the big hardcoded filename should be
Application.StartupPath (so that the path is relative to where the program is)
and since the application is in the bin folder, you have to go back to the solution folder for the file with ".."

mTiles.AddTile(True, Application.StartupPath & "\..\PicTile0.bmp")

After following AddTile, I noticed this line:
Tile.Tile(0).FromFile(Path)

the FromFile() function is a shared property of the Image... and it is a function, not a subroutine. It returns the actual image that comes from the file... and you have to put it in something.
If you want to use a Bitmap, I would go for New Bitmap() since you can easily see what you are doing.

Tile.Tile(0) = New Bitmap(path)

And then, the form shows up... (with nothing on it)... because you aren't drawing anything to it. You are drawing to the CameraFront, but you forgot to draw it to the Paint (or didn't know that you had to do that heh)
But, you have to draw the CameraFront to the form.

You can do this easily by using the .DrawImage property that you get from the event arguments' Graphics member:
e.Graphics.DrawImage(CameraFront, 0, 0)


That gets a black square on the form.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #10  
Old 11-30-2004, 07:13 AM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

follow up from irc chat,

ok so we changed the path to the tile, which fixed the problem of form1 as null (probably the tile that was actually null) to,
Code:
MapTile(0) = New Bitmap(Application.StartupPath & "\..\PicTile1.bmp")
we then added,
Code:
e.Graphics.DrawImage(CameraFront, 0, 0)
to the y =
x =

loop (which we also changed to, )

Code:
            For Y = 0 To tH - 1  'For Y = 0 To map.tiledHeight - 1
                For X = 0 To tW - 1 'For X = 0 To map.tiledWidth - 1
We put the - 1 so it doesnt not draw off my desired (large) map height and width.

I also publically dimmed tH As Long and tW As Long for the loop
then set them as
Code:
tH = Map.H \ TileSize    'Tiled Height
        tW = Map.W \ TileSize   'Tiled Width
in the paint sub routine.

Now, I got a grid with black squares (which is my drawing), but it loads incredibly slow, and I still do not know how to check where to put them.

Here's My Program After what we had worked on last night.

Edit by Iceplug: I had to remove 1 EXE(s) from this attachment.
Attached Files
File Type: zip MapScrolling.zip (23.2 KB, 9 views)

Last edited by Iceplug; 11-30-2004 at 07:21 AM.
Reply With Quote
  #11  
Old 11-30-2004, 07:27 AM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

This line:
e.Graphics.DrawImage(CameraFront, 0, 0)
Does not need to be in the For loops. CameraFront is quite a large bitmap and you are drawing it about a hundred times while it's in the loop, which slows your application down considerably.
Drawing directly to the display is always a slow process.
Moving the e.Graphics.DrawImage line to the outside of the loop should speed it up.

The PictureBox is in the way of the display, however.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #12  
Old 11-30-2004, 10:45 AM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

this worked perfect, but what do you mean picturebox is in the way of display? I was thinking this picturebox will eventually be my character.

I also do not know how to decide which tile goes where when setting up the map.

Last edited by theController; 11-30-2004 at 02:25 PM. Reason: typo
Reply With Quote
  #13  
Old 11-30-2004, 08:58 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

What do you mean by 'which tile goes where'?

Did you put some different values into the map array? Like a '1'? Have you set up some way of drawing different tiles yet?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #14  
Old 11-30-2004, 09:06 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

Quote:
Originally Posted by Iceplug
What do you mean by 'which tile goes where'?

Did you put some different values into the map array? Like a '1'? Have you set up some way of drawing different tiles yet?
no, I do not know how to draw different tiles .

myArray(3, 3) As Integer = {{0+0, 0+1, 0+2}, {1+0, 1+1, 1+2}}

^^ this sets the values of the array individually, so can I not use a bitmap with the same sort of thing?

Code:
myArray(3, 3) As Bitmap = {{Bitmap00, Bitmap01, Bitmap02}, {Bitmap10, Bitmap11, Bitmap12}}
while setting each bitmap previously.

Or is it possible to set a bitmap to an integer value so, 0 = MyBitmap?
and then use the Integer Array?

Last edited by theController; 12-01-2004 at 10:28 AM.
Reply With Quote
  #15  
Old 12-01-2004, 03:36 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Why are you making a two dimensional array of pictures? The pictures should not be forming the actual map array. The map array should be made out of integers, and from the integers you draw the appropriate picture.

The second suggestion is more like it, except you can't set a bitmap to an integer value.
The concept is to get an integer and, from this integer, get a bitmap from it.
So, 0 = grass, 1 = sand, 2 = snow, etc.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #16  
Old 12-01-2004, 05:12 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

Quote:
Originally Posted by Iceplug
Why are you making a two dimensional array of pictures? The pictures should not be forming the actual map array. The map array should be made out of integers, and from the integers you draw the appropriate picture.

The second suggestion is more like it, except you can't set a bitmap to an integer value.
The concept is to get an integer and, from this integer, get a bitmap from it.
So, 0 = grass, 1 = sand, 2 = snow, etc.
So, If int = 0, pic = grass?

How would I draw this in my draw function...

Code:
For Y = 0 To tH - 1  'For Y = 0 To map.tiledHeight - 1
                For X = 0 To tW - 1

                    'Draw tile
                    GFX.DrawImage(MapTile(0, 1), X * TileSize, Y * TileSize)

                Next

            Next
if this is drawing one tile many times, I want to draw a series of tiles?
Reply With Quote
  #17  
Old 12-01-2004, 05:34 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You have to have your tiles in a tileset in order to draw it.
For example, the number that is in the array has to define which image or what part of the tileset you draw from.

number = MapTile(0, 1)
GFX.DrawImage(Bmp(number), X * Tilesize, Y * Tilesize)

If all of your tiles are in one bitmap, then you'd have to extract the appropriate portion of the bitmap to draw.
Rect = New Rectangle(16 * number, 0, tilesize, tilesize)
GFX.DrawImage(Tileset, X * Tilesize, Y * Tilesize, Rect, GraphicsUnit.Pixel)
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #18  
Old 12-01-2004, 07:24 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

When I Dim MapTile
would I do,
Code:
MapTile(,) As Integer = {{0, 1, 1, 1}, {0, 1, 1, 1}}
?

set the integer values of MapTile(0,0) to 0, (0,1) to 1, (0,2) to 1 ?

I dont understand why when I show the value of MapTile(0,1) = 0, and MapTile(0,2) = 0 and MapTile(1,1) = 0 (any number combinations = 0)

so when I put the intCarry = MapTile(X, Y) intCarry will always be 0 therefor always displaying the same picture.


Code:
 Public MapTile(,) As Integer

    Public TileSet(2) As Bitmap

        TileSet(0) = New Bitmap(Application.StartupPath & "\..\PicTile0.bmp")
        TileSet(1) = New Bitmap(Application.StartupPath & "\..\PicTile1.bmp")
          
            For Y = 0 To tH - 1  'For Y = 0 To map.tiledHeight - 1
                For X = 0 To tW - 1

                    intCarry = MapTile(X, Y)

                    'Draw tile
                    GFX.DrawImage(TileSet(intCarry), X * TileSize, Y * TileSize)

                Next

            Next
Reply With Quote
  #19  
Old 12-01-2004, 08:19 PM
Iceplug's Avatar
IceplugMap Movement in BitBlt Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You shouldn't be declaring the MapTile(,) in the drawing sub. It should go elsewhere. In the Form's declaration section is fine.
Have you declared MapTile(,) anywhere else? There should only be one declaration of MapTile which contains the map tile, whether its in the form class or shared in some other class/module.

Then, you get the Map tile indices from that MapTile array. Everything is zero because you are probably using the wrong MapTile.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #20  
Old 12-01-2004, 08:47 PM
theController theController is offline
Centurion
 
Join Date: May 2004
Posts: 120
Default

hmm well it isnt dimmed in the draw function, i just did this to show you how i did dim it..

maybe have a look at the code?

Edit by Iceplug: I had to remove 1 EXE(s) from this attachment
Attached Files
File Type: zip MapScrolling.zip (23.7 KB, 17 views)

Last edited by Iceplug; 12-01-2004 at 09:00 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt Map Movement in BitBlt
Map Movement in BitBlt
Map Movement in BitBlt
 
Map Movement in BitBlt
Map Movement in BitBlt
 
-->