ok sorry it took me so long to get back to you guys, but here is my solution.
class graphics
{
public:
graphics()
{}
graphics(int i)
{FrameSize = i;}
static int getFrameSize()
{return FrameSize;}
int getID () const
{return ID;}
int getFirstFrame() const
{return FirstFrame;}
int getLastFrame () const
{return LastFrame;}
int getHeight () const
{return Height;}
int getWidth () const
{return Width;}
static void setFrameSize (int size)
{FrameSize = size;}
void setID (int id)
{ID = id;}
void setFirstFrame (int frame)
{FirstFrame = frame;}
void setLastFrame (int frame)
{LastFrame = frame;}
void setHeight (int height)
{Height = height;}
void setWidth (int width)
{ Width = width;}
private:
static int FrameSize; // holds the length and width of square frames, should = 16
int ID; //holds the iID of the bitmap that contains the sprite(s)
int FirstFrame; // holds the frame or first frame of animated sprite
int LastFrame; // holds the last from of an animated sprite, a value of 0 means not animated
int Height; // how many frames high the sprite is
int Width; // how many frames wide the sprite is
};
int graphics::FrameSize = 0;
Thats the whole of the graphics class. The Frame size varible is static cause you only need one copy of it. It represents the size of each location in the vector (the vector represents the whole of the "world".) Because the games dbScreenWidth and dbScreenHeight functions count in pixals this serves as a way to measure the map in pixals rather then points in the vector. For me i wanted all my points to be square so i only needed one variable to serve as both height and width, if you want to use rectagles just make a framesize height and framesize width. I also created a map class to hold this, and some other custom data, most of that classes isnt important to the scrolling but a few variables and functions are, and here they are;
int map::BeginX = 0;
int map::BeginY = 0;
int map::ScrollSpeed = 0;
these 3 variables control what part of the universe is being drawn and how fast the screen scrolls. (they are also static cause all you need is one of each of those. This is the loop for drawing, its not that good cause you need to set up a loop for it to work right and i meant to make that into a fuction too i just havent yet so here is the draw function:
void Draw(int i, int j) // i and j will be covered in the loop.
{
if ((pPic->getLastFrame()) != 0)this check if its animated or not
{ dbPlaySprite(pPic->getID(),pPic->getFirstFrame(),
pPic->getLastFrame(), 250); } this plays the animated sprite
else
{dbSetSpriteFrame((pPic->getID()),(pPic->getFirstFrame()));}//this selects the fram for non animated sprites.
dbPasteSprite (pPic->getID(), (i * graphics::getFrameSize()), (j * graphics::getFrameSize())); Then this pastes either to the screen
this is the loop which draws to the screen:
for (int y = 0; y<(dbScreenHeight()/graphics::getFrameSize()); y++)
{
for (int x = 0; x < (dbScreenWidth()/graphics::getFrameSize());x++)
{
if (universe[map::getBeginX()+x][map::getBeginY()+y].getIgnore() == 1)
{;}
else
{universe[map::getBeginX()+x][map::getBeginY()+y].Draw(x,y); }
}
youll notice a varible in there called Ignore (or more specifically the function call .getIgnore) this is because some of my graphics are larger then framesize and i didnt want any overlapping so i made sure not to put graphics data in the coordinates covered by other graphics.
The real "magic" here is the nested loops which supply the x and y values for drawing the vector coordinates on to the screen and that the coordinates drawn coorispond to BeginX and BeginY, so when you want to scroll you just change BeginX and/or BeginY, this will alter the part of the vector that is being drawn to the screen.Further, the limits placed on the loop are governed by the width and height of the screen so that a) you wont draw past the edge of the screen and b)the scrolling will work just fine regardless of resolution. you need to be careful when scrolling that you dont over run the vector, here are my scrolling functions:
void ScrollDown (int UniverseSize)
{
if (map::getBeginY() < ( (UniverseSize - (dbScreenHeight()/graphics::getFrameSize()) ) ) )
{
if ( (map::getBeginY() + map::getScrollSpeed() ) > (UniverseSize - (dbScreenHeight()/graphics::getFrameSize()) ) )
{map::setBeginY( (UniverseSize - (dbScreenHeight()/graphics::getFrameSize() ) ) ); }
else
{map::setBeginY(map::getBeginY()+ map::getScrollSpeed()); }
}
}
void ScrollUp ()
{
if (map::getBeginY() > 0)
{
if ( (map::getBeginY() - map::getScrollSpeed() < 0) )
{map::setBeginY(0);}
else
{ map::setBeginY( (map::getBeginY() - map::getScrollSpeed() ) ); }
}
}
these functions scroll the screen. it also checks to ensure that you dont over run or under run the vector, as this will cause your program to crash with a "fatal error" error. The scrolling left and right functions are virtually identical to the above but with dbScreenWidth instead of dbScreenHeight and they use x instead of y.
ok so that is pretty much the meat and potatoes of a scrolling screen, if this is to complicated let me know and ill send you all the code with my notes that should make it easier to understand, it was hard to fit everything into this tiny box, hope this helps!!!