I'm trying to replace my if and else if statement with a switch statement.
The Ball class comes from an external action script file witch has a variable where I pass in the balls radius(radius = 30).
How would I convert the if and else if statements into a switch statement?
The code:
private var ball:Ball;
private var left:Number = 0;
private var right:Number = stage.stageWidth;
private var top:Number = 0;
private var bottom:Number = stage.stageHeight;
if(ball.x >= right + ball.radius)
{
ball.x = left - ball.radius;
}
else if(ball.x <= left - ball.radius)
{
ball.x = right + ball.radius;
}
if(ball.y >= bottom + ball.radius)
{
ball.y = top - ball.radius;
}
else if(ball.y <= top - ball.radius)
{
ball.y = bottom + ball.radius;
}
Thanks you
else if's. They happen to be faster too.