You know (x, y)
of the object, you also know the (width, height). You know(width, height)
xMin. You know , which is left of your screen, and xMin
xMax`, which is left of your screen, and xMax
, which is right of your screen. If at any time either of these two conditions happens, it is not coming back:
(x + width/2) < xMin
(x - width/2) > xMax
Otherwise it is still within xMin
and xMax
, it will come down in the visible area.
You might need some other solution if the objects are not uniform scale, but this should give you the basic idea.