Frequently Asked Questions


General Code/Logic Questions

Do this:

 

Look at the “UsefuleFiles” folder from any of the week-1 examples (e.g., 1.Speed). You will see the “Resources” folder. Make sure:

 

·         Copy the entire Folder into your project’s Content folder, so in your project’s “Content” folder you will see:

o   Content.contentproj

o   Resources (which has three sub-folders:

§  Textures – can be empty

§  Audio – can be empty

§  Fonts – Arial.spritefont.

See if your messages show up now?

 

       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:

Figure out what you want to do and code accordingly. To support the "event", one way may be:

    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. 

 


Bugs/Features with XGCS1Lib:

XNACS1Rectangle.SetEndPoints(aPos, bPos, Width)

This function has a nasty bug: it re-sets all attributes (shouldTravel, color, emitter, visible, … everything!) for the primitive!! Avoid using this function for now!!
 

XNACS1Rectangle.Collided(aPrimitive, collisionPosition)

CollisiionPosition is supposed to be an approximated collision position. Sometimes, for some reason, collisionPosition seem to always return (0,0). We should avoid using this function, unless you can verify it works otherwise.
 

XNACS1Rectangle.SetTextureSpriteSheet()

Sometimes subsequent tiles in a spritesheet “bleed” into their neighbors. This can be observed when you notice a very thin line at the boundary of your sprite object. In this worst case, this line “blinks” (sometimes showing, sometimes does not show). This is a problem because we support floating point coordinate system while the underlying XNA drawing is based on integer. Here is an example, two 32x32 tiles from a spritesheet. The Red line is located at pixel-32 and should only appear when we draw the right-tile.

Drawing the above left-tile on a 183x183 pixel rectangle looks like:

Notice the thin “red” line to the right of the rectangle. This is “bleeded” over from the right-tile. Unfortunately, this problem is deep in XNA and we do not have a solution to this. The simplest workaround for this problem is to include at least one row/column of transparent pixel between each tile in the spritesheet. In this example, if we replace the red-line by transparent line, the problem can be avoided. [Credit, this problem was identified and analyzed by Jonathan Lynn in May 2011. The above example is provided by Jonathan.]
 

The above will crash because the World-class (XNACS1Base.World) is not initialized.

if (null != mTail) {

mTail.RemoveFromAutoDrawSet();      // tells the library to release the reference

mTail.RemoveEmitterFromUpdateSet();

mTail = null;

}

mTail = new XNACS1ParticleEmitter.TailEmitter(Vector2.Zero … )

A: From any source file, you must include the XNACS1Lib by:

using XNACS1Lib;

And then, you can access to user input by typing the full name to GamePad, e.g., to check for A button click, you can:

            XNACS1Base.GamePad.ButtonAClicked();

To call other library functions, e.g., to clamp to WorldBound:

            XNACS1Base.World.ClampAtWorldBound(yourObject);

A: To test for button pressed events, you do:

if (GamePad.ButtonAClicked()) {

           // Button-A Clicked event has occured ...

 

To poll for current state of button A, you can do:

            if (GamePad.Buttons.A == ButtonState.Pressed)  

           // currently Button-A is depressed

 


Problems relating to XBOX 360:


Problems relating to Windows Phone 7:

o    class MyMP1 : XNACS1Base

and forget to make your class public as it should be:

o    public class MyMP1 : XNACS1Base