Scrolling a tiled map?
-
- 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?
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.
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.
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
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
- Combuster
- 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:
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.
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.
-
- 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:
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.
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.
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
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.
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
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
- Combuster
- 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:
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.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.
Don't say I didn't warn you
Wait...Isn't there a 2005 express edition for VB? If so, I recommend migrating to it, if possibleEdit 2: I think my version of VB6 is extremely unstable
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
-
- 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:
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.
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.