Page 1 of 1

Drawing items to the screen with scrolling

Posted: Sun May 09, 2010 5:18 pm
by Bullet Pulse
In my program, an inventory is a collection of items, not necessarily belonging to the player.

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; }
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 ;)

Re: Drawing items to the screen with scrolling

Posted: Sun May 09, 2010 5:44 pm
by lotios611
It sounds like there's a signed int in there somewhere.

Re: Drawing items to the screen with scrolling

Posted: Sun May 09, 2010 6:01 pm
by Ginto8
lotios611 wrote:It sounds like there's a signed int in there somewhere.
you mean unsigned ;)

Re: Drawing items to the screen with scrolling

Posted: Tue May 11, 2010 5:45 am
by lotios611
Ginto8 wrote:
lotios611 wrote:It sounds like there's a signed int in there somewhere.
you mean unsigned ;)
Oops, I must of looked to fast.