Mapper Issues

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
thegamefreak0134
Extreme Poster
Posts: 455
Joined: Mon 23 Jan, 2006 10:09 pm
Location: In front of a Computer, coding
Contact:

Mapper Issues

Post by thegamefreak0134 »

Ok, this should be a quickie. In VB.NET, I am developing a mapper. When the user clicks on a tile and then clicks on the map, I want that tile to go in the clicked-upon location. Simple right? I already know how to get the place they clicked, so picking the right tile is no prob. I do, however, need to know this.

I have the map currently set up as one image. I want to take the tile image (from a file, but can be loaded into a bitmap object if neccessary) and "draw" it onto the map image. Do I have to do this by pixel using a series of loops, or is there a drawing command to do this for me? I was going to do it like I always do with an array of pictureboxes, but VB.NET took that nice feature away and hid it, so I reckon there must be an easier way. Thanks for any help or suggestions!

-gamefreak
I'm not mad, just a little crazy.

DarkNova - a little side project I run.
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

I've made so many map editors in VB, it's ridiculous. They pretty much all share the same source code though.
Here's the source to its latest iteration: Bubble Bobble Map Editor. (sorry, it's VB5, not 7)
http://home.comcast.net/~alanweiss3/dwe ... ubmap2.zip

My approach is to make 4 picture boxes:
One picture box for the container of the tilemap
One picture box for the tilemap.
Scrollbars, they move the tilemap around inside the container.
One picture box for the tileset container
One picture box for the tileset
Map draws by copying tiles from the tileset to the tilemap.
The tileset container is just there to allow scrolling.

The user interface I made was inspired by RPG maker. You left click to draw, and right drag to pick up a bunch of tiles into the 'brush'. You can also use the tile palette to set the 'brush' to a single tile.

I also threw in some never-used stuff like the "Tile Replacer", which replaces all tiles with another, used when you change the tileset but need to update an old map.

To draw tiles, use either bitblt or PaintPicture. For VB7, try AllegNet, it's based on the famous Allegro C/C++ graphics/sound/etc library.
http://www.skorzec.com/allegnet/
You know your hexadecimal output routine is broken when it displays the character 'G'.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

With VB7+, use GDI+ (the standard graphics system). Graphics.DrawImage will blit an image for you. To get a Graphics object for a picture box (let's say it's called MapEditBox) use CreateGraphics() - Graphics g = MapEditBox.CreateGraphics();, g.DrawImage(MyOtherPictureBox.Image, 0, 0);

I'm not sure what you mean by no picture box arrays, you can still use them (though not through the form designer)... (C# syntax, but you get the idea):

Code: Select all

PictureBox[] PictureBoxArray = new PictureBox[3];

for (int i = 0; i < 3; ++i) {
    PictureBoxArray[i] = new PictureBox();
    this.Controls.Add(PictureBoxArray[i]);
}
Might be a better idea to load the tile images into an ImageList control, then use a ListView control to display the tile 'picker'.

(Still not switched to VB8 [2005] yet?) :(
User avatar
thegamefreak0134
Extreme Poster
Posts: 455
Joined: Mon 23 Jan, 2006 10:09 pm
Location: In front of a Computer, coding
Contact:

Post by thegamefreak0134 »

So basically take a graphics object for the image I want to draw onto and use Graphics.DrawImage(attributes) to draw another image? And it lets me define x and y positions a such? If so, this is exactly what I need. Thanks!

-gamefreak
I'm not mad, just a little crazy.

DarkNova - a little side project I run.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Exactly. DrawImage has lots of different method signatures, allowing you to do everything from simply blitting one onto the other to scaling it as well to even clipping.

One thing I would warn you is that by default the graphics object will use high quality settings - so it will filter things when you scale them up and treat everything with a half pixel offset. I suggest setting g.PixelOffsetMode to PixelOffsetMode.Half and g.InterpolationMode to InterpolationMode.NearestNeighbor.

If you are using Graphics to draw to an Image or Bitmap rather than to a control, you don't use CreateGraphics. You use Graphics g = Graphics.FromImage(WhateverImageYouAreUsing);
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

So. why do you want this, tgf?
Image
User avatar
thegamefreak0134
Extreme Poster
Posts: 455
Joined: Mon 23 Jan, 2006 10:09 pm
Location: In front of a Computer, coding
Contact:

Post by thegamefreak0134 »

I'm making a mapper to design the levels (world map) for my pokemon re-make. (which is still alive and well btw, thanks to greyscale finally working in an APP. thanks to jim e.)

I got it to work (not excellent or anything, but it will be OK for my uses.) but still have one issue. It's so dang slow!

I have it reading all the pictures from file as it draws them. This basically just allows my saved maps to be smaller, but I may not really need to do this. Any other thoughts on how to speed it up?

-thegamefreak
I'm not mad, just a little crazy.

DarkNova - a little side project I run.
User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

You might want to think about buffering your pictures somewhere, reading everything from file all the time might be cause for a slow down.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

Why not use EM instead of building your own? *ducks* (yes, shameless plug)
Image
User avatar
thegamefreak0134
Extreme Poster
Posts: 455
Joined: Mon 23 Jan, 2006 10:09 pm
Location: In front of a Computer, coding
Contact:

Post by thegamefreak0134 »

Because by building my own, I can have it export not only the map data, but the tile info, the actual tile data, ect. I can even go so far as to make it export the behavior codes for each tile type, so I edit it all in the program instead of trying to do it all by hand. That way to add a tile, I simply re-export the entire thing rather than trying to swim through my code. It's a very nice system, and goes so far as to ensure that I don't make silly typos more than once.

Anywho, I will attempt to buffer picture data somewhere, since that seems to be the only hold-up. Thanks again. First map is already on it's way. Woo!

-gamefreak
I'm not mad, just a little crazy.

DarkNova - a little side project I run.
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

uhm. EM can export the tileinfo and tiledata also :P ah well, suit yourself
Image
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Post by chickendude »

If it'll make you feel any better, I'll use EM solely from now on :)
Post Reply