• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
fatjaba

Scrolling buffer in a tile engine

12 posts in this topic

Hi, I have a question that hopefully someone can help me with. I have been reading about tile engines for a while now and all the articles I seem to read say blit the tiles straight to the screen, but using offsets to allow for smooth scrolling. This I understand. However, on a limited device say a pda/mobile phone this is not possible due to the limited amount of draws you can do per refresh. So what I heard you can do is make an offscreen buffer and then only draw this, so you would scroll the buffer and draw only the buffer to the screen making it much faster. However, my problem is this, say the buffer is only one tile width larger than the screen of the device, what happens when you have scrolled one tile width and you run out of buffer to update? I think i may be being stupid, but some help would really be appreciated! ------------------------- | | | |-----------------| | | | screen | | | | | | | | | | | |-----------------| | | buffer | |------------------------
0

Share this post


Link to post
Share on other sites
I think you're just trying to implement double buffering, in which case you wouldn't scroll the buffer, you'd scroll whatever you're drawing to the buffer.

The back-buffer should be the same size of the screen, whatever that may be. You draw everything to it (to limit the number of screen-draws) and when the frame is done, you blit the entire back-buffer to the screen, thus resulting in a single screen-draw. Makes things much smoother on computers (no flickering).

GameTutorials.com has some Win32 tutorials using .Net that demonstrate double-buffering. Haven't looked through it myself, but it may be of some use. Basically, just treat the buffer like you would have were it the screen, and when finish, swap the buffers (blit it to the screen).

Have fun!
0

Share this post


Link to post
Share on other sites
Doesn't that problem exist if you have drawn your tiles directly to the screen, only in that case you'd run out of tiles instead of buffer? You'd just have to either make sure you don't scroll the buffer too far, or tile the buffer, depending on whether you want the world to be limited to within a certain bounds or youd want it to wrap around.
0

Share this post


Link to post
Share on other sites
Treat the backbuffer like it's circular (i.e. a two dimensional ring buffer), when scrolling you just wrap around the edges and blit any new tiles on the other side. Finally you copy the buffer to screen in four separate pieces.

And the result is unlimited four-directional scrolling without using any extra copying!
Am I the only 386 coder left around here? ;)
0

Share this post


Link to post
Share on other sites
doynax, thats exactly the kinda thing I wanted to hear, can you explain that to me in a bit more detail, or point me in the direction of a tutorial/article on it?

Thanks for the replies guys!
0

Share this post


Link to post
Share on other sites
Quote:
Original post by fatjaba
doynax, thats exactly the kinda thing I wanted to hear, can you explain that to me in a bit more detail, or point me in the direction of a tutorial/article on it?
Okay.. here's an example.

This is the original screen that you want to display (with tiles A through D)
0123
----
ABCD
ABCD
ABCD
ABCD
The slow way of left scrolling this buffer would be to copy the whole thing one step to the left and then bring in a new column tiles (E).

0123
----
BCDE
BCDE
BCDE
BCDE
The fast way is instead of actually copying all of the data we only replace the column that scrolled out (A) with the new one (E).
0123
----
EBCD
EBCD
EBCD
EBCD
The idea is that you view the buffer as if it extends infinitely to the right but repeating the same data every fourth column.

0|1230|1230123...
-+----+----------
E|BCDE|BCDEBCE...
E|BCDE|BCDEBCE...
E|BCDE|BCDEBCE...
E|BCDE|BCDEBCE...
When displaying this buffer we have to blit it to screen in two parts. Map buffer column 1-3 onto screen column 0-2 and buffer column 0 to screen column 3.

Things get a bit more complicated when scrolling multi-directionally, but it's really not that hard.
If you need more help I could probably post some sample code.
0

Share this post


Link to post
Share on other sites
That's a great way to do it doynax, and I did actually think about that, I was just trying to present a simple double-buffering method.

It should be noted though, that if you want to have the actual world larger than a single buffer (you mentioned it's tile-based, so I'm assuming it is), you'll need to make the back-buffer 1 column and 1 row larger than the screen, or you'll get black spaces on the screen when you do smooth scrolling.

With 2-dimensional scrolling, you'll also need to do as many as 4 blits to the screen.

Edit:
Sorry, you'll either get black spaces or you'll get part of the column from the other side of the screen, and assuming it's not a donut world, that's not what you want.
0

Share this post


Link to post
Share on other sites
I think I get it this time, but some sample code would be very much appreciated as well.

Thanks again!
0

Share this post


Link to post
Share on other sites
Quote:
Original post by fatjaba
I think I get it this time, but some sample code would be very much appreciated as well.

I wrote some sample code, didn't get much sleep tonight though so there's probably a few dozen bugs in it..

Everything is specified in whole tiles and it only handles horizontal scrolling. If you need fine scrolling just make the buffer one tile wider to offset the screen blit within (like overflowed_ described).

// The screen's width
enum { Size = 40 };

// Current position. Initially offscreen so that the first call draws the whole buffer
int CurPos = -Size;

// Draw a column in the tile map at MapPos onto BufPos in the scroll buffer
void DrawColumn(int MapPos)
{
// calculate buffer position
int BufPos = MapPos % Size;

// draw the individual tiles
...
}

void ScrollTo(int NewPos)
{
// Only draw the columns once when scrolling more than a screen at a time
if(abs(NewPos - CurPos) > Size)
{
CurPos = NewPos - Size;
}

// Draw the new columns
if(CurPos < NewPos) {
// scroll left
while(CurPos < NewPos) {
DrawColumn(CurPos++ + Size);
}
} else {
// scroll right
while(CurPos > NewPos) {
DrawColumn(--CurPos);
}
}
}

void DisplayBuffer() {
int RSize = CurPos % Size; // Calculate the left buffer block's size
int LSize = Size - RSize; // The remainder is the right block's size

// Blit both blocks to screen
BlitToScreen(RSize, 0, LSize);
BlitToScreen(0, LSize, RSize);
}

// Blit a part of the buffer to screen
void BlitToScreen(int BufPos, int ScreenPos, int Size);





[Edited by - doynax on October 20, 2004 6:14:49 AM]
0

Share this post


Link to post
Share on other sites
Im still not entirely sure I understand that code, with the drawcolumn part are you not going to end up drawing a lot of columns to the buffer? or are the columns tiles of width 1?
0

Share this post


Link to post
Share on other sites
Quote:
Original post by fatjaba
Im still not entirely sure I understand that code, with the drawcolumn part are you not going to end up drawing a lot of columns to the buffer? or are the columns tiles of width 1?

All coodinates are specified in whole tiles, not pixels. Infact the code doesn't deal with pixels at all.
So DrawColumn(3) with a tile width of 16 draws a column of tiles at pixel 48.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0