Screen Wrap a Moving Object

Review

If statements are one of the most powerful, and basic building blocks of any programming language. Remember that computers are just number crunchers... deep down the computer is simply adding, subtracting and comparing numbers.

An if statement checks whether one value is greater than, less than, or equal to another value. The if statement returns one of two possible values: true or false.

We then tell the computer what we want it to do when the if statement returns true.

What We Did

  1. Created a new file called ball_wrap
  2. Used an if statement to check if the Y position of ball1 was greater than a number
  3. Set the Y position of ball1 to 0 if the if statement returned true
  4. Created a top boundary variable equal to 0
  5. Created a bottom boundary variable equal to the height of the Stage

Important ActionScript

if(ball1.y>boundryBottom){
  ball1.y=boundryTop;
}

Self-Check for Understanding

Have a look at the following code:

When would the explode function be called?

-->It's called whenever the X position of myShip is less than X position of enemy<--