Vote count:
0
I don't understand why I'm getting this error message, when I've clearly assigned a value to p1, as you can see in the following code:
public class AppMain
{
private static GraphicsContext graphics;
private static bool running;
private static Sprite bckgnd1, bckgnd2;
private static Sprite openScreen, instructScreen, gameOverScreen;
private static Vector3 pos1, pos2, pos3, pos4, pos5;
private static Player p1, p2;
private static Fruit apple, orange, banana;
private static Stopwatch clock;
private static long startTime, stopTime, deltaT;
private static Random rand;
enum GameState {
opening,
instructions,
play,
gameOver};
private static GameState currentState;
private static List<Player> pList;
public static void Main (string[] args)
{
Initialize ();
while (running == true) {
startTime = clock.ElapsedMilliseconds;
SystemEvents.CheckEvents ();
Update ();
Render ();
stopTime = clock.ElapsedMilliseconds;
deltaT = stopTime - startTime;
}
}
public static void Initialize ()
{
running = true;
pList = new List<Player>();
graphics = new GraphicsContext ();
Texture2D pTex1 = new Texture2D("/Application/Assets/macmuffin.png", false);
Texture2D pTex2 = new Texture2D("/Application/Assets/macmuffin1.png", false);
pos1 = new Vector3(200, 600, 0);
pos2 = new Vector3(400, 600, 0);
Player p1 = new Player(pTex1, pos1, 1, graphics, "Player 1");
Player p2 = new Player(pTex2, pos2, 2, graphics, "Player 2");
pList.Add (p1);
pList.Add (p2);
}
Also, bonus points if you can tell me why when I try to render the players, the error message "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at Cain_Game3.AppMain.Main (System.String[] args) [0x00000] in :0" shows up. Thanks.
asked 1 min ago
Field 'XXX.AppMain.p1' is Never Assigned to, And Will Always Have Its Default Value Null
Aucun commentaire:
Enregistrer un commentaire