Scrolling a tiled map?

Programming, for all ages and all languages.
Post Reply
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Scrolling a tiled map?

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post 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.
My OS is Perception.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post 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 :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post 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 :)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post 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'?
C8H10N4O2 | #446691 | Trust the nodes.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I personally actually prefer VB6 and friends over the .NET versions of VB.

.NET is overrated, imho.
Post Reply