Sign in to follow this  

SDL funkyness

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im probably doing one of those miss-the-little-details things, but here it goes. These are the three functions.

void Player::draw()
{
	if ( mDrawn == 0 )
		mDrawn = 1;

	SDL_Rect dest;
	dest.x = x;
	dest.y = y;
	
		
	SDL_BlitSurface( mBack, NULL, mScreen, &dest);
}

// SDL_BlitackSurface( src, clipbox, dest, location );
				
void Player::clearBG()
{
	if( mDrawn == 1 )
	{
		SDL_Rect dest;
		dest.x = OldX;
		dest.y = OldY;
		dest.w = sW;
		dest.h = sH;
		SDL_BlitSurface( mBack, NULL, mScreen, &dest);
	}
}

void Player::updateBG()
{
	SDL_Rect srcrect;
	srcrect.w = sW;
	srcrect.h = sH;
	srcrect.x = x;
	srcrect.y = y;
	OldX = x;
	OldY = y;
	SDL_BlitSurface( mScreen, &srcrect, mBack, NULL);	
}



they are called in this order (say by player object) player.clearBG(); player.updateBG(); player.draw(); It isnt exactly drawing anything. I know the .png file is loading properly because if i just do a draw function it works fine (short of the 'tail' on the sprite). mScreen = the buffer mBack = the image sH = mBack->h sW = mBack->w mDrawn is init to 0 default All i get is black screen via this code, but if i play with the SDL_BlitSurface src and dest images i get a werid mix of duplicate sprites and/or cutting off of the sprites in weird places. Any help would be appreciated.

Share this post


Link to post
Share on other sites
Are you flipping the screen? SDL_FLip(screen)

also why is screen a private variable in Player (does the m mean private member? I don't know hungarian notation)?

and you shouldn't do "if drawn==1: do whatever" but just "if drawn: do whatever"

when you say duplicate sprites, maybe it's because you are just blitting the sprite and not the BG? so the previous sprite is not getting erased.

Share this post


Link to post
Share on other sites
Flipping yeah

mScreen is really just the buffer. its assigned through a pointer in the init function

im trying not to blit the entire background every flip, cause that would take forever, just trying to blit the background to the old location of the sprite to erase it. something in the order of the blitting is getting messed up and that 'OldX, Y' blit is covering the new sprite blit..frustrating.

Share this post


Link to post
Share on other sites

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this