Your thoughts on Scrolling Dilemma

Started by
6 comments, last by Bagpuss 21 years, 4 months ago
OK, i have written a basic tile editor / Tile Engine in OGL using MFC, but am playing around with the scrolling. As I see it, there are 2 methods of scrolling, I can either draw an area 1 tile bigger than my scroll area, and draw it outside my viewport as below. |-----------------------| | | | | |-|---| | | | | | |-|---| | |-----------------------| Or I can Draw just the visible area (no diagram needed I guess !) Now, as I see it, drawing more that the visible area will take up more memory but be easier for me on the coding (I can scroll in any direction by moving the scrollbars and just updating the array and drawing outside my viewport). Or, I can draw exactly to my viewport, which takes more code but will save memory. Now I am not sure which is the best method, and is better (for modern computer systems), less memory useage, or more memory useage and harder programming for me. Any comments (if I even make sense) Bp.
Advertisement
Well your diagram didnt really help
You can A) draw one tile outside the viewport

or B) when you scroll to the left you only need draw one extra tile on the right and visa versa. Same with scrolling up and down.

Because you look at the way the tiles move. You dont add a tile to the end every time it scrolls, only when the next tile comes into view.

So say i have
offsetx; // this is the offset of the tile
and offset x is nonzero then you need to draw an extra tile. Then you find out which way you went and and draw the extra tile on the appropriate tile.

I just thought of B) then so if it doesnt work to well :|
Do not remove a fly from your friend's forehead with a hatchet.Chinese Proverb
I guess I am trying to find the best optimisation, either

A) to draw extra tiles outside the viewport (or partially outside the view port) which will take up extra memory in storing the bitmaps and other data.

Or b) Having more code to just draw the bits of tiles I require.

I think there will be more code in B), but A will take more memory. But A) will easily allow me to scroll in diagonal directions or follow player movement than B where I will need a complex scrolling algorithm or a lot of scrolling functions (ScrollLeft(),ScrollRight(),ScrollUp(),ScrollUpLeft() etc.

My question is In your opinions will anyone with a modern PC notice any performance loss with me having to store more in memory, or with me having a bigger program will there be a noticeable speed loss.

As an aside, (this is mostly theoretical at the moment) is there any way I can measure the speed my program is running at (or any diagnostic libraries I can include ?), either just the speed of certain functions or the speed of the whole.

Thanks,

Bp.
Well, how big is a tile compared to the screen?

If it''s like an old console game where each tile is like 16x16 and the screen is 256x256, then I would just draw the extra tiles off the edges (it won''t take up *that* much more memory, and besides, it''s a game -- it''s SUPPOSED to gobble RAM!).

If one of your tiles takes up half of the visible area, then I would probably opt for only drawing what you need to.

Take into account that it will be slower to do the visible area check if you have 500 tiles to draw than if you have 16.


Usually, you don''t need to worry about code size vs. memory, it''s speed vs. memory.
I''d surely go for the extra tiles method. It''s faster and easier to code, while the extra memory problem is not that big. few extra kilos


---
novocaine thru yer veinz
---novocaine thru yer veinz
I had this same problem so i experimented with both. The speed loss just drawing the visible area, even if almost unoticeable, will still be more of a performance sacrifice than to just use the extra memory. My screen resolution was 640x480 by the way.
...and that's where I saw the leprechaun...he told me to burn things.
How fast will the game be scrolling?

a single pixel in any direction per frame...or the possability of scrolling across multiple tiles with each frame?

If you are intending to scroll quickly...then drawing only what you need will allow for much more consistant frame rates...not to mention makeing the engine much simpler as the same tile "clipping" routines can be used for sprites and what not (don''t forget that even doing the other method, some sprites will likely need to be "clipped" when moveing outside the drawing area)...besides the checks needed to "clip" tiles are very simple (and only really apply to the four outside edges...while the bulk of the tiles can be blitted without any "clipping" checks)
Thanks to all of you htat have replied. Th eproject has been on hold due to work commitments, but when I get time to restart it, I will think hard about what you all have said.

Thanks,

Bp

This topic is closed to new replies.

Advertisement