I am working on a 1945 plane game. I have got a bullet to hit a plane and then draw collision sprite but then it redraws the plane sprite again. I want it to black out the plane sprite after the collision sprite is drawn for a brief period of time. I am using the sleep function to make a small delay. here is the code I am working on.
OpenGL doesn’t know anything about the scene you’re trying to render. You don’t “turn on” or “turn off” anything. You draw what you want to draw for the frame you want to draw it in. And if you don’t want to draw it that frame, then you don’t draw it that frame.
So you “turn off” a sprite by not drawing it. You still have to draw everything else. So sleeping in the middle of your loop is not helping anyone.
Yes. You’re doing it. Your drawScene() function is being called repeatedly in a loop. It’s just that with GLUT, the loop is behind-the-scenes in glutMainLoop().
Don’t want to be rude, but maybe you should spend some time in learning more about programming in general (especially object oriented programming). It does not make any sense to program a game if you don’t know the simple basics. If somebody gives you an answer that solves the problem (what Alfonse Reinheart already did) you will end up asking the next question about some basics in a few days because you didn’t learn them. You should get a good book or a fitting Internet source and start reading and programming tutorials. If you don’t understand some things in a tutorials you can always ask here but you need to learn them before trying to make a game (even a simple one).
So to give you a hint, what you can do:
Create a class called “Plane” which stores information about the plane like its position or if it is alive. It provides functions which give you information about its current status and to modify the status. It might even have a function which draws it like your function “drawScene_plane_one()”. Then you could put something like the following into your code function:
// ... somewhere in your definitions section
class Plane
{
// ... fill with details about a plane
}
// ... somewhere during initialization declare an instance of Plane
Plane plane1;
// ... in your draw scene
if(plane1.isAlive())
{
plane1.draw(); // draw plane, cause it is not dead
}
else
{
if(plane1.isExploding) // if it is exploding, draw a fireball, if not, don't do anything
{
plane1.drawExplosionAnimation();
}
}
...
This is just an example what you can do and not necessarily the best way to do things. Anyways, try to do it like that. You probably need to do some tutorials before you are able to implement the missing class code. Try for example this one: Object Oriented Programming in C++ - Gillius's Programming
well before I use classes I am going to implement some Boolean values. I have almost solved my problem. I am able to draw a plane then shoot it and draw a collision sprite, all I want to do next is black out the collision sprite.