if (mBall.CenterX < 0f){
PlayACue("BelowZero");
}
How come my audio cue
plays continuously?
A: Because you did not update
the mBall.CenterX position after you play the audio cue. Your logic here
says, if mBall.CenterX is less than 0, then play the audio cue. Whenever
this condition is true, the audio cue plays. Here you need to figure out
when you want to play the cue:
if (mBall.CenterX < 0f) {
PlayACue("BelowZero");
mBall.RemoveFromAutoDrawSet(); // Make the ball disappear
mBall.CenterX = 1f;
// ... later on your logic should/may decide to
// add the ball back to the auto draw set
}
if (mBall.CenterX == 4f){
PlayACue("TouchesFour");
}
I can see my ball fly across the X=4f line, but the audio cue won't play,
why?
A: Do not test for floating
point equality! The chance of a general floating number equal to another one
is close to zero! In general, you can only test for floating point
equality when you have specifically set a variable to a well known constant
(e.g., X==0f). Otherwise, you should test for inequality. In this case, you
can test for if your CenterX is greater than 4f.
public class ClassExample : XNACS1Base
{
float a = World.WorldDimension.X;
}