forums

TNT Basic Forums > Programming Q&A
Scrolling maps
< Last Thread     Next Thread >
Author
Thread        Post A Reply

12-20-2001 17:38

Posted by:
Jon

Click Here to Email Jon   Find more posts by Jon

Hi all,

I am using the following code to scroll my map:

Procedure DrawMap (float ScrollAmt)
int smallAmt,bigAmt

bigAmt = ScrollAmt/32 'How many tiles to scroll
smallAmt = ScrollAmt-(bigAmt*32) 'part of a tile

Draw Map Section bigAmt,0 to (bigAmt+21),15,0 to -smallAmt,0 'Draw scrolled map

end proc


The problem is that it is rather slow on OS X. Is there a better way to scroll a REALLY LARGE map without using too much memory?

Thanks,
Jon

12-20-2001 18:37

Posted by:
Jim

Click Here to Email Jim   Find more posts by Jim

would this method "use to much memory?"

How about just drawing the map once to a canvas that is the size of the entire map, and then just scrolling a viewport the size of the screen across the canvas using the Set Viewport Offset command? I believe this is the method used in the scrolling demos.

12-20-2001 19:06

Posted by:
Jon

Click Here to Email Jon   Find more posts by Jon

That was my first thought as well. But I was concerned that the canvas would use too much memory for a really large map. Does anyone know a rough estimate of how much memory a canvas uses (say per 32x32 pixel square)?

If it is smaller than I assumed, that would be great. If not, I am thinking about using a combined approach. That is make a rather large canvas to scroll around in, and fill it with map. Then when the player comes near the edge of the map piece, fill the canvas with a different offset of the map and reset the scroll.

Do you think this would work? Do you think I am just being paranoid about the memory usage?

Thanks,
Jon

12-21-2001 08:49

Posted by:
John Treece-Birch

Find more posts by John Treece-Birch

Scrolling

I don't think you're being paranoid about memory usage of a big canvas. You don't want to open a canvas as big as your world because that would use up a ridiculous amount of memory.

Fortunately, there is a trick that can be done which makes scrolling much faster than redrawing the map every frame and uses hardly any more memory.

Basically, you open a canvas that is one tile bigger than the screen in each direction. You draw all the tiles that are just in the area around the player. Then you can scroll around that but when the player's screen hits the edge of the canvas you move them back to the middle and then redraw the map tiles around the player's new offset. It can take a bit of messing with to get it just right, but the final effect should look like there is a large area to scroll around.

It's hard to explain in words so I'll make a simple example project over the next few days that demostrates all this. Keep your eyes on the examples page :)

Thanks,
John

12-22-2001 02:01

Posted by:
JMD

Click Here to Email JMD   Find more posts by JMD

I look forward to seeing that example. I think that method of scrolling might come in handy for my own project!

01-16-2002 01:48

Posted by:
Jim D

Click Here to Email Jim D   Find more posts by Jim D

Are you still planning on making an example to illustrate this technique? It's OK if you're not, I'm just curious. Perhaps I will see if there is more info on this method of scrolling out on the internet, I'm sure there is.

01-19-2002 10:41

Posted by:
Mark Tully

Find more posts by Mark Tully

Opps..

That's my fault, John gave me the example last week but I've been so busy this week I've not had chance to put it on our site... sorry, expect it soon!

Mark

01-23-2002 14:06

Posted by:
Mark Tully

Find more posts by Mark Tully

Tile Scrolling Example online

Sorry about the delay, the tile scrolling example is now online, it is packaged in with the existing scrolling examples and can be downloaded directly from this link:

http://www.tntbasic.com/download/examples/files/Scrolling_Examples.sit

Hope this helps!

Mark

01-24-2002 12:28

Posted by:
ERaZer

Find more posts by ERaZer

Speed...

Hmm, that was cool but I'm wondering how fast that is. I couldn't get more then 20 fps(Yes, I changed the framerate) when scrolling, and when I use the normal(outdoor scrolling example) way I get solid 30 fps(perhaps more, haven't tested) when I scroll a area that is 1200*1600.
Oh, I just realized this uses 16*16 tiles, and mine uses 32*32...
But still, how fast is this?

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.