Skip to main content
gamedev.net
🔒 Locked

2d scrolling?

Started by baronvondude 2 replies 400+ views
Original Post
baronvondude
baronvondude
Hello, I'm new to direct X and I'm starting out with direct draw before i move to any 3d stuff. Anyway, I'm using direct X 7 to progmam with and I was wondering if anyone knew of any books or tutorials that taught scrolling? I understand how to get pixals drawn to the screen, about the back buffer and pretty much all the basics but I can't seem to figure out scrolling. I don't really want anything complex, just have the background constantly loop would be great. Anyway, Thank you
AfroFire
AfroFire
Simply change the coordinates of the rectangles you are drawing to when someone pushes a button.

So if I have a bunch of tiles with grass textures on them, and I want to simulate walking - When the person pushes the right arrow button to walk (+ direction) I will move the tiles left (- direction) to make them scroll.

so just say rectangle.x -= 2; // or whatever your speed is.

Simple way of putting it.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
matthughson
matthughson
Might I suggest skipping over DirectDraw all together? It's pretty much abondonware now, and honestly I think its harder to use than D3D! I would strongly suggest picking up Focus On: 2D in Direct 3D. It's very well written, to the point, cheap, and best of all looks at things from a 2D perspective so its very easy to understand. But then, when you are ready to try some truly 3D stuff, the gap you have to cross is much smaller.

Either way, best of luck!

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Supernat02
Supernat02
I would tend to agree with Matt. It is good to understand direct draw and how it worked, the concepts of buffer flipping and vertical refresh and retrace, but after that, get into D3D. It may not profit to spend as much time learning DirectDraw as it would to go ahead and start learning Direct3D.

If you are still interested though, here's how I handled scrolling.

Background Looping:
You know how wide the texture is that will scroll. You know how wide the screen is (both in pixels). You start out with scroll_x = 0.

int x = scroll_x;for (int y=0; y < screen_height; y++)  for (int i=0; i < screen_width; i++)  {    // PutPixelFromTexture(int XScreen, int YScreen, int XIndex, int YIndex);    // This takes texture pixel at (x, y) and puts it on screen at (i, y).    PutPixelFromTexture(i, y, x, y);    // Move to the next pixel.    x++;    // If you've reached the end of the texture, start over at the front of it.    if ((x % texture_width) == 0)      x = 0;  }


Now just increment scroll_x each frame or every second or whatever.
Chris ByersMicrosoft DirectX MVP - 2005

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.