Preventing an object from spawning off-camera

MonjiOMonjiO Member Posts: 20
edited November -1 in Working with GS (Mac)
So, I'm working on a shooter game and I'm trying to prevent enemy attacks from coming from offscreen, while still destroying themselves once they reach the edge of the screen. I've got the camera as an object with its own dimensions and it is detected for the purposes of player movement.

Detailed Explanation:
The player is moving from left to right, with enemy projectiles coming from right to left. Currently, I have a rule stating:

If self.position.x < game.CamOriginX
Then Destroy Actor

So the projectile is destroying itself once it hits the left edge of the screen. However, currently, enemies are able to attack based on timers meaning that attacks can (and are!) coming from outside the camera range.

So, my question is basically how best to prevent this sort of behavior. Should I redo how enemies are attacking so that they won't attack while offscreen? If so, how? Or is there a way to make the projectile destroy itself while not in the camera's view?

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    Is your camera moving at a constant speed? You could track the camera's position in the game and use that to prevet the attack.

    if spawner is <= CAMERAPOSITION
    spawn

    and just set cameraposition to whatever value you want, the camera's exact position, or maybe 100 higher so they spawn a little offscreen?
  • MonjiOMonjiO Member Posts: 20
    Hmm, interesting suggestion. I'll give it a shot and tell you what happens!
Sign In or Register to comment.