Ah, yes, it definitely helps to limit the number of things drawn to only what can be drawn on the screen. I’m glad you figured it out, nice!
If what you have is working, definitely keep moving forward!
For the sake of conversation though, consider that you can further optimize your tile drawing. Currently you’re looping through the entire set of background tiles, then checking to see if it’s on the screen before you draw it. I’m not sure how your tileset data is arranged, but you might consider having it arranged in a logical order, with reference to the screen, inside your background tiles array. Then, you can cheat and only draw what’s on the screen from the array directly.
Consider the case where your tiles are arranged in a two dimensional array where each array index is an x and y tile position. You can calculate the starting tile indices, as well as how many tiles are on the screen in both the x and y directions. Now your for loop can iterate over only the tiles that are being shown on the screen.
Like I said, if what you have is working, roll with it! No need to optimize something that doesn’t need to be optimized. Just something to keep in the back of your mind though in case you find you need it down the road.