Skip to main content
GameDev.net gamedev.net
🔒 Locked

scrolling problem

Started by Brad8383 Dec 4, 2001 at 1:28 PM 0 replies 200+ views
Original Post
Brad8383
Brad8383
The problem is it doesnt work. I have a scrolling function Scroll(int x, int y); The 2 variables are Upperleft(the tiles thats the upper left tile to be rendered) and scrollpix(upperleft pixel within the tile). it works perfectly when i scroll in positive directions but i cant seem to reverse it to work right in negative directions. for positive directions the code is.... if(x > 0) { Mapinfo->UpperLeft.x += (Mapinfo->ScrollPix.x + x)/Mapinfo->TileSize.x; Mapinfo->ScrollPix.x = (Mapinfo->ScrollPix.x + x)%Mapinfo->TileSize.x; } my idea for the negative directions was if( x < 0) upperleft.x += (scroll.x + x)/tilesize.x; int remainder = (scroll.x + x)%tilesize.x; if(ramainder == 0) { scroll.x = 0; } else { upperleft.x--; scroll.x = tilesize.x - remainder; } } but this just doesnt work. any ideas?
kmsixpence
kmsixpence
For one, you shouldn''t have to do tests for if it is greater or less than zero. If you have a negative for the x/y, and you add it to the current, adding a negative number is the same as subtracting a positive number so you don''t need to do the tests.
This is the code I would use. Its smooth scrolling too. By the way, this doesn''t use the scollpix because shouldn''t they be the same?

  
int Scroll(int x, int y)
{
if(x!=0){Mapinfo->UpperLeft.x+=x;}
else
return(false);

if(y!=0){Mapinfo->UpperLeft.y+=y;}
else
return(false);

return(true);
}

Topic Locked

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

Sign in to reply to this topic.