Collision between an object and the edge of the screen

Hello. I want to know how to set up a collision between an object and the edge of the screen. If at the literature on this is welcome

You can simply do something like this: if (x < 0 || y < 0 || x + width > screenWidth || y + height > screenHeight) if you want to know if the object is leaving the screen and then do what you want with this information, like clamping the object to the screen bounds.

1 Like