A couple of things…
First off, it may help to separate your thinking into two parts… the world, the place where your objects actually are, and the view, the place where you project what the screen should actually be seeing. The world can have any dimension and be any size; however, the screen is always going to have a top-left coordinate at 0,0 and a bottom right corner at whatever your screen dimensions are. Consider the difference in coordinates between your world and your view
Next, your approach is a great first step! You’ve correctly identified that there are things that you want to render, and things that you don’t want to render. You’ve also created a way of determining whether or not you should render it. This can go a step further though… consider how you want to check to see if those things should be rendered. With your current approach, you have to check all of your objects… there are ways that you can skip checking objects that aren’t on the screen entirely!
Here’s two ways to consider…
- You can organize your objects into an array where the indexes of the array have meaning in relation to their position in the world. For example, consider a tile based game where you have a 100x100 array of tiles. If your view is in the top-left of the world and can only show a 16x16 section of tiles, you only need to consider the first 16 tiles horizontally, and the first 16 tiles vertically, in your tile array. This can be extended to start from any position and render whatever size you need.
- There are other data structures besides an array that can be used to organize, and retrieve data. Look into a QuadTree. It splits up virtual space into sub-divided rectangles based on how many things are in each rectangle. You can then query the QuadTree for objects that intersect with a specified rectangle (ie, the screen). This approach is really good for objects that can be in any position in space and generally aren’t contiguous, such as enemies. There’s lots of resources about QuadTrees, and MonoGame.Extended even has an implementation built in, if you’re using that.
Do keep in mind that with either of these options, you will probably still want to touch on them in your update loop since you may still need to update their positions or state, regardless of whether or not they are on the screen.