Detect Sprite Leaving Camera View

In my game, I have a sprite (mainCharacter) that is controlled by the user and a camera that follows the mainCharacter. I also have another sprite (object) that does not move with the camera or the mainCharacter. When the mainCharacter walks far enough that the object is no longer in the camera view and thus cannot be seen by the user, I want to trigger an action. How would I go about doing this?

I currently have four sprites (edges) that are anchored to the four sides of the screen/camera view. When the object collides with one of the edges, an action is triggered. However, in order to keep the edges stationary, I put the edges in a separate layer than that of the camera, object, and mainCharacter - although this strategy doesn’t seem to work.

Can’t you check the object’s position, relative to the center of the camera?
If object.X() < CameraX()-(SceneWindowWidth()/2)
Something like that.

2 Likes

I could, thanks! I also just noticed the “destroy when outside of the screen” behavior.