Skip to main content
Missing back-tick was making the formatting look wrong
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

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 xMinxMax`, 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:

  1. (x + width/2) < xMin
  2. (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.

You know (x, y) of the object, you also know the (width, height). You know xMin, 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:

  1. (x + width/2) < xMin
  2. (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.

You know (x, y) of the object, you also know the (width, height). You know xMin, 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:

  1. (x + width/2) < xMin
  2. (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.

Source Link
starikcetin
  • 5.3k
  • 4
  • 26
  • 60

You know (x, y) of the object, you also know the (width, height). You know xMin, 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:

  1. (x + width/2) < xMin
  2. (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.