 |
|

11-28-2004, 05:50 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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 08:05 PM.
Reason: I fixed my problem
|

11-29-2004, 07:24 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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. 
|
|

11-29-2004, 09:25 AM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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 01:56 PM.
Reason: I fixed my problem
|

11-29-2004, 05:28 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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. 
|
|

11-29-2004, 05:37 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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
|
Last edited by Iceplug; 11-29-2004 at 06:38 PM.
|

11-29-2004, 05:42 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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()  .
|
|

11-29-2004, 05:43 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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?
|
|

11-29-2004, 06:33 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
sorry, the other one included a large bitmap...
Edit by Iceplug: I had to remove 2 EXE(s) from this attachment
|
Last edited by Iceplug; 11-29-2004 at 06:41 PM.
|

11-29-2004, 06:55 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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.
|
|

11-30-2004, 06:13 AM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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.
|
Last edited by Iceplug; 11-30-2004 at 06:21 AM.
|

11-30-2004, 06:27 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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.
|
|

11-30-2004, 09:45 AM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
|
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 01:25 PM.
Reason: typo
|

11-30-2004, 07:58 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
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?
|
|

11-30-2004, 08:06 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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 09:28 AM.
|

12-01-2004, 02:36 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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. 
|
|

12-01-2004, 04:12 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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?
|
|

12-01-2004, 04:34 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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)

|
|

12-01-2004, 06:24 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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
|
|

12-01-2004, 07:19 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
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. 
|
|

12-01-2004, 07:47 PM
|
|
Centurion
|
|
Join Date: May 2004
Posts: 120
|
|
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
|
Last edited by Iceplug; 12-01-2004 at 08:00 PM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|