Page 1 of 1

Scrolling a tiled map?

Posted: Wed Oct 10, 2007 1:31 am
by pcmattman
Hi everyone,

For a school project, I'm making a simple RPG. I have to use VB6 because that's all that the school has in the way of programming tools (I could use C but then I'd miss out on class time on the project).

I want to have the map scrollable (but keeping the player in the center of the screen) as it is topdown and tiled (16x16 tiles, just bmp files for now).

Is there any way to do this in VB (not .NET either)? I'm assuming I use a PictureBox but that's as far as I've gotten so far.

Posted: Wed Oct 10, 2007 1:49 am
by AJ
Hi,

Would it complicate things too much to use DirectX? I have certainly done the same task before and once you have got past all the initial setup code, it makes things much better (double buffering, rescaling etc...). You can even use a picturebox as your container, if you like!

I think if you do it without, the only way is to draw the next frame to a hidden picture box and then toggle the .visible property, which is sloooow!

Cheers,
Adam

Posted: Wed Oct 10, 2007 1:53 am
by pcmattman
Hmmm... I'll look into using DirectX - I can use the hwnd of the PictureBox as the hwnd of the window for the surface.

For scrolling I'm still a bit stuck, is there any simple (and fast) way to go about doing that? A generic algorithm is fine with me.

Posted: Wed Oct 10, 2007 3:36 am
by Combuster
there are a few alternatives - both can be used with native vb6, windows gdi and directx

1) you render each frame again and again. slowest but also the easiest.
2) you keep a copy of the background, move it around when necessary, then draw the exposed edges.
3) you store the entire playing ground in a backbuffer, and draw only the part you find necessary.

since we're talking 2D here, you'll be required to use DirectX 7. I hope you have at least XP or things can get really nasty (personal experience: directx7 under '98 is like a minefield: one misstep and you can start over). You can not use debugging features, and non-fullscreen rendering like what you are saying is especially a pain. Things have eased up quite a bit with dx8 but then you're forced to do all the graphics 3d-style which is even more involved and still not failsafe.

with plain vb you can use a hack though: create a frame and put an image on top of it. if you move the image only the part contained in the frame will be visible.

You can use the same method with gdi calls. Its hardly any faster but less of a hack. Besides you can do transparent images that way (see calldlls.vbp in the examples directory).

Although directx is potentially faster, the issues that come along with it make it a potential hell, which is probably not worth the trouble considering the size of your project (at least, what I can see from your description).

I have lots of sourcecode leftovers from my own experiments - if you want them just leave me a note. Before you do however I expect you to consider how much that interferes with the rules of your assignment.

Posted: Wed Oct 10, 2007 3:43 am
by pcmattman
I have a document open at the moment outlining how to use DX7 with VB (it seems reasonably simple, and I now have an idea as to how I'll go about doing the scrolling and it mixes well with that).

If it becomes too difficult, though, I'll resort to slower, but simpler drawing methods.

I spent all afternoon trying to convince VB6 to work properly (the form designer kept crashing) so I haven't been able to attempt the DX7 implementation. Now I realize it was a corrupt form file, which has since been fixed.

Edit: same site as the DX7 tutorial, but I just found this: http://gpwiki.org/index.php/DirectX:Dir ... ling_Tiles.

It's basically just what I've been looking for.

Edit 2: I think my version of VB6 is extremely unstable... The form designer keeps doing something to my forms making them unusable. which causes VB to crash. No idea why this happens either, once it crashes once the form is never usable again. I also can't test the programs, for some weird reason that crashes VB as well.

Posted: Wed Oct 10, 2007 5:55 pm
by AndrewAPrice
Have an X and Y map offset. Then use basic collision test to see if each of the map tiles are within the screen at render time.

Posted: Thu Oct 11, 2007 1:50 pm
by neon
For smooth scrolling a tilemap, al you need to do is determine how much of the tiles to render on screen (by using an offset variables for x/y offsets into a tile, you can clip the edges of the edge tiles by rendering the smaller portion of the tile)

Also, provide a routine that can render a part of a tile.

I don't know how to do it in VB, but this might help:

Clicky

Good luck :)

Posted: Thu Oct 11, 2007 2:29 pm
by Combuster
pcmattman wrote:Edit 2: I think my version of VB6 is extremely unstable... The form designer keeps doing something to my forms making them unusable. which causes VB to crash. No idea why this happens either, once it crashes once the form is never usable again. I also can't test the programs, for some weird reason that crashes VB as well.
Given that you are working with DX7, I wouldn't consider that unusual. Old Microsoft produce has a tendency to be nasty. If the problem persists if you remove ALL directx references and code then your installation is screwed, otherwise you know where it came from.

Don't say I didn't warn you :wink:

Posted: Thu Oct 11, 2007 3:44 pm
by neon
Edit 2: I think my version of VB6 is extremely unstable
Wait...Isn't there a 2005 express edition for VB? If so, I recommend migrating to it, if possible :)

Posted: Thu Oct 11, 2007 3:46 pm
by pcmattman
Our school only has VB6 :(

Turns out my installation of VB6 is gone bad, I installed the VB5CCE and tried using that and I had no problems (still don't).

Now I have a scrolling map as well, although it doesn't scroll smoothly (which I don't really need it to do anyway). All I have to figure out now is how to keep the player in the center of the screen at all times and then I can concentrate on game logic instead of visuals.

Posted: Thu Oct 11, 2007 4:01 pm
by Combuster
neon wrote:Wait...Isn't there a 2005 express edition for VB? If so, I recommend migrating to it, if possible :)
Another one of those people who think that VB.NET can be compared to VB5/6. Its a different language. :cry:

Posted: Thu Oct 11, 2007 4:09 pm
by Alboin
pcmattman wrote:Our school only has VB6 :(
Maybe you could get them to convert to something more 'new'... Or even, dare I say it, 'free'?

Posted: Fri Oct 12, 2007 12:37 am
by pcmattman
I personally actually prefer VB6 and friends over the .NET versions of VB.

.NET is overrated, imho.