That is only a half correct solution to the problem. What if the bullet goes out on the left side and not on the right? What if it leaves the screen in the Y dimension but not the X dimension? You’re going to have to make it a bit more complicated than that, although if you think about it, it is really easy to implement.
Something like this would get the job done:
if(bullet.x < 0 || bullet.x > camera.getViewportWidth()
|| bullet.y < 0 || bullet.y > camera.getViewportHeight())
bullet.destroy();
Although this code is pretty trivial, there are some things to watch out for when you’re going to try to implement that:
What does your bullet’s X and Y parameters represent? The lower left corner of the bullet? The middle of the bullet? Or something else?
The other thing that you should keep in mind is that this solution is only going to work if you are NOT going to move the camera itself away from (0;0). If you want to move your camera away from (0;0) you’ll have to move the boundaries too in the if statement.
However, even if you implement this feature correctly (so it will always destroy the bullets that are outside of the camera’s viewport) it is not guaranteed to give you the desired effect. What if an enemy is outside of the camera’s viewport but there are no obstacles to block the bullet? The enemy should receive damage from the bullet, but he won’t because you remove the bullet before it could even hit him.
Also, nothing guarantees that your camera will be always around your player. What if you have to move away the camera from the player to somewhere else (for example to an exploding helicopter in a scripted event)? Bullets that are already around won’t hit your player because (similarly to the previous problem where it was the enemy who couldn’t get damaged) the bullets won’t reach him before they get destroyed.
You could go around these things by using a bit bigger boundaries than your camera’s viewport but it could still result in weird effects when opponents are far away from the camera.
What I could suggest is to make boundaries for your entire level and check if the bullet left the level itself (or collided with something, etc.) and then remove it. 