Side Scrolling(Up and down)

I’m trying to make my game so that once you go higher than the top of the screen, the screen will begin to scroll with you, but I have no idea how to do this, the current method that i have right now, checks to see if the player’s y value is lower than 0, and if it is, then it adds to my Y offset. but it just keeps adding and adding. Any help with this?

In my approach I’ll take use of bufferimage and swap it to roll. But it’s hard to maintain and use lots of memory.

Are you sure it’s not checking and adding an offset but the player’s y is always less than 0?

Yeah you probably want to have an offset based on the screen or player position in your drawing methods so you can cancel out the difference and have things remain visible.