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();
}
}
}
Weapon fire refuses to show up!
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
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)).
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)).
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):
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
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
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!
And thank's that solved it! :D Cheers!
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement