Jump to content
  • Advertisement
Sign in to follow this  
Tynnhammar

Weapon fire refuses to show up!

This topic is 4765 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

Greetings! I'm trying doing a space invader clone, however I've run in some trouble in the process of writing the weapon code. The problems is that the bullet creates and it does enter the for loop but it doesn't show up. Please take a look at what might be wrong, because I've checked everything I know :/. full code,zipped, here
Units.cpp --> where the CBullet class exists

CBullet::CBullet()
{
	Alive = true;

	Display = SDL_GetVideoSurface();

	BulletV = 3;

	BulletIMG = SDL_LoadBMP("ship.bmp");
	
	BulletSrc.w = 47;
	BulletSrc.h = 30;
	BulletSrc.x = 0;
	BulletSrc.y = 0;

	BulletDest.w = 47;
	BulletDest.h = 30;
	BulletDest.x = 300;
	BulletDest.y = 300;
};

CBullet::~CBullet()
{
	SDL_FreeSurface(BulletIMG);
};

void CBullet::Show()
{
	SDL_BlitSurface(BulletIMG, &BulletSrc, Display, &BulletDest);
};

void CBullet::MoveUp()
{
		BulletDest.y -= BulletV;
};

void CBullet::CheckCollision()
{
	/*                  if(BulletDest.y = 20) bla bla
	{
		NOT IMPLEMENTED YET
	}
	*/
};

GAMELOOP.cpp
while(gamerunning)
{
                if(KeyHeld[SDLK_SPACE])
		{
			CBullet* newBullet = new CBullet;
			Bullets.push_back(newBullet);
		}
		if(Bullets.size() > 0)
		{	
			for(iter = Bullets.begin(); iter != Bullets.end(); ++iter)
			{
				(*iter)->MoveUp();
				(*iter)->Show();
				(*iter)->CheckCollision();
			}
		}
}

Share this post


Link to post
Share on other sites
Advertisement
Where is the full source? Could you give us a direct link?

You probably use doublebuffer (you use SDL_DOUBLEBUF flag at SDL_SetVideoMode). Check that you have SDL_Flip(screen) at the end of main loop (screen is your video surface (SDL_Surface *foo)).

Share this post


Link to post
Share on other sites
Ok, so it seems that you don't use double buffering(http://www.gamedev.net/dict/search.asp?Term=double+buffer). I recommend you to use it like this:

First you have to change your SDL_SetVideoMode()-function (from init.cpp):
From: Display = SDL_SetVideoMode(Width, Height, BitDepth, SDL_ANYFORMAT);
To: Display = SDL_SetVideoMode(Width, Height, BitDepth, SDL_ANYFORMAT|SDL_DOUBLEBUF);

And then add SDL_Flip(Display); line to the end of main loop (gameloop.cpp):

if(Bullets.size() > 0)
{
for(iter = Bullets.begin(); iter != Bullets.end(); ++iter)
{
(*iter)->MoveUp();
(*iter)->Show();
(*iter)->CheckCollision();
}
}

SDL_Flip(Display);






Other way is use "single buffering" and use function SDL_UpdateRect(), but double buffering is bettre way so if you want to use "single buffering", you have to read SDL_UpdateRect()'s info from SDL:s manual (www.libsdl.org).



Edit. Uups, there isn't -tag :)
Edit2: Nice character encoding problem :) Edit3: Not anymore... intresting

Share this post


Link to post
Share on other sites
I would like to know more of the different "modes", ie what does SDL_DOUBLEBUF and the other means?

And thank's that solved it! :D Cheers!

Share this post


Link to post
Share on other sites
Quote:
Original post by Tynnhammar
I would like to know more of the different "modes", ie what does SDL_DOUBLEBUF and the other means?

Did you read this: http://www.gamedev.net/dict/search.asp?Term=double+buffer


You can find the full list of modes from SDL's documentation: http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!