Drawing items to the screen with scrolling
Posted: Sun May 09, 2010 5:18 pm
In my program, an inventory is a collection of items, not necessarily belonging to the player.
When I load up the game, any items that were given a negative coordinate, end up at 0,0.
Also, when the items should scroll off the screen, because I'm walking in the other direction, they just end up at the edge of the map.
It's almost as if they refuse to become negative.
If you could help me figure this out, I would be very grateful
Code: Select all
void Inventory::Draw(SDL_Surface *surface)
{
for each (Item *i in items)
{
i->setY(i->getY()+ Level::getScrollY());
i->setX(i->getX() + Level::getScrollX());
if (i->getX() < System::SCREEN_WIDTH || i->getY() < System::SCREEN_HEIGHT)
i->Draw(surface);
i->setY(i->getY() - Level::getScrollY());
i->setX(i->getX() - Level::getScrollX());
}
}
void Item::Draw(SDL_Surface *surface)
{
SDL_BlitSurface(this->surface, &srcRect, surface, &dstRect);
}
int getX() { return dstRect.x; }
int getY() { return dstRect.y; }
void setX(int x) { dstRect.x = x; }
void setY(int y) { dstRect.y = y; }
Also, when the items should scroll off the screen, because I'm walking in the other direction, they just end up at the edge of the map.
It's almost as if they refuse to become negative.
If you could help me figure this out, I would be very grateful