Vertical Scrolling Help

Started by
17 comments, last by Droopy 15 years, 8 months ago
Quote:Original post by xM1k3x
You guys have both helped me tremendously and I now have it scrolling correctly. Only one thing seems weird once the window reaches the top of the map it begins to flash and look weird. Any ideas as to why? Like why doesnt it just stop moving and thats it?

Also what would be the best way to make the map go on for a while at least 2 mins worth of scrolling?

Thank you all so much I am learning alot from you guys.


Is it flashing to black, up and down, what? Weird in what way? Up and down would probably be because of the way you reset your scroll and speed variables. Black, or anything else, I don't know.

Timing: determine how many animation frames you want the scrolling to last (2mins * framesPerSecond), then divide the number of pixels of the level by that number. That's how many pixels you move per frame.

Advertisement
Or you'll have to loop the data when you're accessing the tile map. If the currently requested index is beyond the tile map, it is wrapped around to the begining, so your data will scroll continuously for ever.

For example:
const int GRIDWIDTH = 20;const int GRIDHEIGHT= 20;const char TileMap [GRIDWIDTH * GRIDHEIGHT] = { . . . };char GetTile(int width, int height){  //the following line will make sure actualHeight is always < GRIDHEIGHT  // no matter how large height may get. look up "modulus operator"  int actualHeight = height % GRIDHEIGHT;  //locate tile in map  return TileMap[GRIDWIDTH * actualHeight + width];}


It is probably flashing because once you go past the ends of the buffer, nothing tells it to stop. So then you start accesing invalid parts of memory which will have "random" data values. As your code interprets this it would probably appear to "flicker."

The solution I showed you should fix that, provided that width was passed within bounds, [0, GRIDWIDTH-1].
Quote:Original post by bzroom
Or you'll have to loop the data when you're accessing the tile map. If the currently requested index is beyond the tile map, it is wrapped around to the begining, so your data will scroll continuously for ever.

For example:
const int GRIDWIDTH = 20;const int GRIDHEIGHT= 20;const char TileMap [GRIDWIDTH * GRIDHEIGHT] = { . . . };char GetTile(int width, int height){  //the following line will make sure actualHeight is always < GRIDHEIGHT  // no matter how large height may get. look up "modulus operator"  int actualHeight = height % GRIDHEIGHT;  //locate tile in map  return TileMap[GRIDWIDTH * actualHeight + width];}


It is probably flashing because once you go past the ends of the buffer, nothing tells it to stop. So then you start accesing invalid parts of memory which will have "random" data values. As your code interprets this it would probably appear to "flicker."

The solution I showed you should fix that, provided that width was passed within bounds, [0, GRIDWIDTH-1].



Quick question you didnt show exactly what you were passing through to the getTile function I am assuming you are passing in the width and height of the tile itself is this correct?

Thanks
Quote:Original post by bzroom
It is probably flashing because once you go past the ends of the buffer, nothing tells it to stop. So then you start accesing invalid parts of memory which will have "random" data values. As your code interprets this it would probably appear to "flicker."


Shouldn't that make it segfault?
Are you double buffering and not clearing buffers before useing them?
Quote:Original post by MSW
Are you double buffering and not clearing buffers before useing them?


Im not really sure actually if thats whats happening. Is the flickering a problem that could be caused by not clearing the buffers?

Sorry if I sound newbish its because I am , and I am just learning all this stuff.
You really need to describe exactly how the screen is flickering and looking wierd. And for good measure, post your latest version of UpdateScrollPostion(). It's most likely that when you fixed the scroll direction, you broke the bits that check for the edges of the world, or something like that.

It's unlikely that a double buffering issue would crop up just now. It is possible, stranger things have happened to me, but I don't think you need to worry about it.

Quote:Quick question you didnt show exactly what you were passing through to the getTile function I am assuming you are passing in the width and height of the tile itself is this correct?


It appears he actually meant the coordinates of the tile. So in DrawTiles() you would do something like "tilenum = GetTile(x, y)".
http://lazyfoo.net/SDL_tutorials/lesson21/index.php

This helped me out tons with 2d scrolling. It's written for SDL but it should at least point you in the right direction for DirectX
Quote:Original post by MSW
change this:
//draw tiles onto the scroll buffer surface
for (y=0; y<=rows; y++)

to this:
//draw tiles onto the scroll buffer surface
for (y=rows; y<=0; y--)


I'm coming in late on this one, but since no one else has pointed it out, it will work better if you make it "y>=0" in the second sample >.<

This topic is closed to new replies.

Advertisement