Skip to main content
Inspiring
April 12, 2014
Question

Loop using external variables

  • April 12, 2014
  • 2 replies
  • 410 views

I need to make a loop, which keeps a spawned item within the boundaries of the screen. It needs to be like this:

if (square_x + (width/2) > 480)

            {

                square_x = square_x - 5

            }

(square_x is a variable defined before the conditional) but it needs to be a loop, so that it keeps repeating that effect until it satisfies the statement: "square_x < 480"

This topic has been closed for replies.

2 replies

Inspiring
April 12, 2014

Why do you need a loop? Why not to just position object within boundaries?

Are you talking about initial positioning or keeping object within boundaries while animating it?

Ned Murphy
Legend
April 12, 2014

If you need it to loop, then you might just try using a while loop...

while(square_x >= 480){

   if (square_x + (width/2) > 480){
      square_x = square_x - 5
   }
}