Hi i am making a simple pool game and have my balls in an array (each ball runs through a class to set the properties. i have a Texture2D property to set the texture so i can set the white ball colour and yellow and red ball colour. however i have set up the array and try to draw but it will not accept the array property as a texture it keeps saying it is of null value even though i have set each of the balls here is the code below as you may understand a little more.
//ball class for each ball public class balls{
public Texture2D tex; public float x; public float y; public Vector2 v = new Vector2(); public float r = 12.5f; public float m = 10;}
//array of balls
balls[] pBalls = new balls[] {new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls(), new balls()};//setting the ball sprite batch and texture for a red ball
sBalls =
new SpriteBatch(this.graphics.GraphicsDevice); ContentManager BallsLoader = new ContentManager(Services);tBalls = BallsLoader.Load<
Texture2D>("RedAlpha") as Texture2D;pBalls[0].tex = tWBall;
for (int i = 1; i < 16; i++){
pBalls[ i].tex = tBalls;//space there for forum use only
}
tWBall is white ball same code as above but whit texture and different variable names where needed.
//sprite batch for balls b.tex is the texture that is set but this is where the error keeps showing foreach (balls b in pBalls){
sBalls.Begin(
SpriteBlendMode.AlphaBlend);sBalls.Draw(b.tex,
new Rectangle((int)b.x, (int)b.y, 25, 25), Color.White);sBalls.End();
}i hope the code is clear enough for you all. if you have any questions or would like the full cs code file let me know and i will send it to you.
Regards
Mark