I have a cloud and a man sprite, these are both drawn separately but for some reason they are drawing together and overlapping and then positioning themselves at the defined places for both of the sprites.
My sprites class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace MarioFake
{
class Sprites
{
public Vector2 MarioPosition = new Vector2(200, 200);
private Texture2D MarioStill;
public Vector2 LargeCloudPosition = new Vector2(100, 100);
private Texture2D LargeCloud;
public void LoadContent(ContentManager theContentManager, string theAssetName)
{
MarioStill = theContentManager.Load<Texture2D>(theAssetName);
LargeCloud = theContentManager.Load<Texture2D>(theAssetName);
}
public void Draw(SpriteBatch theSpriteBatch)
{
theSpriteBatch.Draw(MarioStill, MarioPosition, Color.White);
theSpriteBatch.Draw(LargeCloud, LargeCloudPosition, Color.White);
}
}
}
and my drawing method in my Game class:
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
MarioStill.Draw(this.spriteBatch);
LargeCloud.Draw(this.spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
The sprite class doesn't need to hold information for both Mario and the cloud, if you create a generic sprite class like this ..
public class Sprite
{
public Vector2 Location;
public Texture2D Texture;
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(Texture, Location, Color.White);
}
}
you can create your mario and clouds like this.
Sprite Mario = new Sprite() { Location = new Vector2(200, 200), Texture = Content.Load<Texture2D>("MarioTexture") };
Sprite Cloud = new Sprite() { Location = new Vector2(100, 100), Texture = Content.Load<Texture2D>("CloudTexture") };
and draw them as you previously did.
Mario.Draw(spriteBatch);
Cloud.Draw(spriteBatch);
Here is an example of a full game class that demonstrates loading and rendering both sprites.
public class Sprite
{
public Vector2 Location;
public Texture2D Texture;
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(Texture, Location, Color.White);
}
}
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
List<Sprite> sprites;
Sprite mario, cloud;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
// Create the sprites.
sprites = new List<Sprite>();
mario = new Sprite() { Location = new Vector2(100, 100), Texture = Content.Load<Texture2D>("MarioTexture") };
cloud = new Sprite() { Location = new Vector2(200, 200), Texture = Content.Load<Texture2D>("CloudTexture") };
sprites.Add(mario);
sprites.Add(cloud);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
foreach (var sprite in sprites)
sprite.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
}
Related
I'm just starting with Monogame and I'm trying to make a simple sprite, which later is meant to be a button. I've searched all around and done several tutorials, but I can't make it work. I just keep getting the blank, blue screen. Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
namespace Test_Game
{
class Main_Menu
{
//setting the variables
public Texture2D button1;
public Vector2 button1Pos;
public GraphicsDevice graphicsDevice;
GraphicsDeviceManager graphics;
public void initialize(Texture2D texture, Vector2 position, ContentManager Content)
{
//Getting the initialized stuff
button1 = Content.Load<Texture2D>("button_temp");
button1Pos.X = 30;
button1Pos.Y = 30;
}
public void Draw(SpriteBatch spriteBatch)
{
graphics.GraphicsDevice.Clear(Color.Black);
spriteBatch = new SpriteBatch(graphicsDevice);
//Just drawing the Sprite
spriteBatch.Begin();
spriteBatch.Draw(button1, new Rectangle(30, 30, 214, 101), Color.White);
spriteBatch.End();
}
}
}
Hope you can find an answer.
I can see many mistakes in your code, I would left a comment pointing all of the, but its too long.
Most of the mistakes come from this: you're not inheriting from Game class. Your line class Main_Menu should be class Main_Menu : Game. Always use this template for a game class:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MyGame
{
public class MyGame : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
}
From here on, you must fill this template with the following in mind:
Create your memory-only objects in the Initialize method;
Load and create file-related objects in the LoadContent method;
Add your game logic in the Update method;
Add your drawing logic in the Draw method;
Usually, do not bother with the constructor or the UnloadContent method.
Connecting your existing code with the template, we get the following:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Test_Game
{
public class Main_Menu : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Vector2 buttonPos; // our button position
Texture2D button; // our button texture
public MyGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
buttonPos = new Vector2(30, 30); // X=30, Y=30
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
button = Content.Load<Texture2D>("button_temp"); // load texture
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
// here we would add game logic
// things like moving game objects, detecting collisions, etc
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
// draw our button
int buttonWidth = 214;
int buttonHeight = 101;
spriteBatch.Draw(button, new Rectangle(buttonPos.X, buttonPos.Y, buttonWidth, buttonHeight), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
This template is used in every game for the MonoGame and XNA frameworks, so you should find a LOT of content on the web about what each method of the Game class does.
First of all, im new to shaders and xna.
I've been trying to follow this tutorial:
http://www.xnahub.com/simple-2d-lighting-system-in-c-and-monogame/
I've done everything he said, I even ended up copy/pasting some parts to be totally sure although – it still won't work.
sampler s0;
texture lightMask;
sampler lightSampler=sampler_state {
Texture=<lightMask>;
}
;
float4 PixelShaderLight(float2 coords:TEXCOORD0):COLOR0 {
float4 color=tex2D(s0, coords);
float4 lightColor=tex2D(lightSampler, coords);
return color * lightColor;
}
technique Technique1 {
pass P0 {
PixelShader=compile ps_4_0_level_9_1 PixelShaderLight();
}
}
The problem is that when I apply the pass 0 everything goes black.
My guess is that the lightcolor is returning zero. The lightmask is a renderTarget where I've painted my lights on.
I really dont know why lightcolor would return zero. If that is the case, could anyone give me a hint in what I'm doing wrong?
Here is my main class if you want to look at it:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace TestingGame
{
public class TestingGame : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Location loc;
public static Texture2D lightMask;
public static Texture2D img;
public static Effect effect1;
RenderTarget2D lightsTarget;
RenderTarget2D mainTarget;
public TestingGame()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
loc = new Location(20,20);
var pp = GraphicsDevice.PresentationParameters;
lightsTarget = new RenderTarget2D(
GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
mainTarget = new RenderTarget2D(
GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
lightMask = Content.Load<Texture2D>("lightmask.png");
img = Content.Load<Texture2D>("img.png");
effect1 = Content.Load<Effect>("lighteffect");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
if(loc.Equals(new Location(21,20)))
System.Console.WriteLine("Working");
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(lightsTarget);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
spriteBatch.Draw(lightMask, new Vector2(20, 20), Color.Red);
spriteBatch.End();
GraphicsDevice.SetRenderTarget(mainTarget);
GraphicsDevice.Clear(Color.Transparent);
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
spriteBatch.Draw(img, new Vector2(50,50));
spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
effect1.Parameters["lightMask"].SetValue(lightsTarget);
effect1.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
For the others like me who stumble upon this problem, you need to use the complete signature for the pixel shader as stated here : http://www.software7.com/blog/pitfalls-when-developing-hlsl-shader/
So the correct code for this shader is the following :
sampler s0;
texture lightMask;
sampler lightSampler=sampler_state {
Texture=<lightMask>;
};
float4 PixelShaderLight(float4 pos: SV_POSITION, float4 color: COLOR0, float2 coords: TEXCOORD0): SV_TARGET0 {
float4 color=tex2D(s0, coords);
float4 lightColor=tex2D(lightSampler, coords);
return color * lightColor;
}
technique Technique1 {
pass P0 {
PixelShader=compile ps_4_0_level_9_1 PixelShaderLight();
}
}
Hi guys i have a little problem.
I have this 2 DrawableGameComponets (bigApple, smallApple) in both I'm drawing into a RenderTarget and then draw the RenderTarget in the backbuffer but this happens independently in each DrawableGameComponent.
The thing I want to achieve is that both DrawableGameComponents draw properly one in top of another.
Something like this:
This it's the screen with both drawableComponent with no rendertargets in each component.
But instead of that I get this:
This it's the screen with both drawableComponent with rendertargets in each component.
This is for a little game I'm working on. I'm planning to display in one drawable component and image from the camera and in the other drawable gamecomponent the game itself. But once I add another GameComponent to the Componets List, the one above the last added can't be seen.
This is the Code from each drawable Component.
SmallApple:
public class SmallApple:DrawableComponent2D
{
Texture2D apple;
public SmallApple(Game game)
: base(game)
{
//Do nothing
}
protected override void LoadContent()
{
apple = Game.Content.Load<Texture2D>("apple");
this.Size = new Vector2(apple.Width,
apple.Height);
renderTarget = new RenderTarget2D(GraphicsDevice,
(int)Size.X,
(int)Size.Y,
false,
SurfaceFormat.Color,
DepthFormat.None,
this.Game.GraphicsDevice.PresentationParameters.MultiSampleCount,
RenderTargetUsage.PreserveContents);
base.LoadContent();
}
public override void Initialize()
{
base.Initialize();
}
public override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 1f, 0);
this.SharedSpriteBatch.Begin(SpriteSortMode.Immediate, null);
this.SharedSpriteBatch.Draw(this.apple, this.Position, Color.White);
this.SharedSpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
this.SharedSpriteBatch.Begin();
this.SharedSpriteBatch.Draw(apple, this.Position,Color.White);
this.SharedSpriteBatch.End();
base.Draw(gameTime);
}
}
--
And the BigApple Class
public class BigApple:DrawableComponent2D
{
Texture2D apple;
public BigApple(Game game)
: base(game)
{
}
protected override void LoadContent()
{
base.LoadContent();
apple = Game.Content.Load<Texture2D>("apple");
this.Size = new Vector2(apple.Width, apple.Height);
renderTarget = new RenderTarget2D(GraphicsDevice,
(int)Size.X,
(int)Size.Y,
false,
SurfaceFormat.Color,
DepthFormat.None,
this.Game.GraphicsDevice.PresentationParameters.MultiSampleCount,
RenderTargetUsage.PreserveContents);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
public override void Draw(GameTime gameTime)
{
GraphicsDevice.SetRenderTarget(renderTarget);
GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 1f, 0);
this.SharedSpriteBatch.Begin(SpriteSortMode.Immediate,null);
this.SharedSpriteBatch.Draw(this.apple, this.Position, Color.White);
this.SharedSpriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
this.SharedSpriteBatch.Begin();
this.SharedSpriteBatch.Draw(renderTarget,new Rectangle((int)Position.X, (int)Position.Y, (int)GraphicsDevice.Viewport.Width, (int)GraphicsDevice.Viewport.Height), Color.White);
this.SharedSpriteBatch.End();
base.Draw(gameTime);
}
}
The class DrawableComponent2D is the one that contains the heritage from drawablegameComponent and has some variables to work with.
What is your XNA version?
If you use XNA 3.1 maybe your problem is here GraphicsDeviceCapabilities.MaxSimultaneousRenderTargets property
Solved!!. i have to add a method to the delegate:
graphics.PreparingDeviceSettings;
so this is the method:
private void GraphicsDevicePreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) {
e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
}
And to add it to the graphicsDeviceManager is just one line:
graphics. PreparingDeviceSettings += GraphicsDevicePreparingDeviceSettings;
voilà!!! Thanks for your support
I am trying to make Pong in XNA/C# using a class for the Paddle and Ball
Game1.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Pong
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Paddle Paddle1 = new Paddle();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
Paddle1.Draw();
base.Draw(gameTime);
}
}
}
Paddle.cs:
namespace Pong
{
class Paddle
{
SpriteBatch spriteBatch;
ContentManager Content;
Texture2D paddle1;
Texture2D paddle2;
Vector2 Paddle1;
Vector2 Paddle2;
public void LoadContent()
{
paddle1 = Content.Load<Texture2D>("pongpaddle1");
Paddle1 = new Vector2();
Paddle1.X = 50;
Paddle1.Y = 50;
}
public void Draw()
{
spriteBatch.Begin(); //Causes NullReferenceException was unhandled, Object reference not set to an instance of an object.
spriteBatch.Draw(paddle1, Paddle1, Color.White);
spriteBatch.End();
}
}
}
I don't have anything in the Ball class yet, but it will use similar methods to Paddle.cs
Every time I've ran the code, I keep getting a System.StackOverFlow exception whenever it hits this line of code in Game1.cs:
Paddle Paddle1 = new Paddle();
How do I fix this? I don't see how it's run out of memory already.
EDIT: Updated code.
What's happening here is that Paddle inherits Game1. Game1 creates new Paddles:
Paddle Paddle1 = new Paddle();
Paddle Paddle2 = new Paddle();
Those Paddles are Games that need to initialize their own set of Paddles. Infinite recursion! I'm not sure how XNA works, but if that's how the inheritance should be, just move your initializations to Initialize():
// TODO: Add your initialization logic here
base.Initialize();
this.Paddle1 = new Paddle();
this.Paddle2 = new Paddle();
I kind of doubt that a game object should inherit from the game itself, though. That would seem like a rather poor design decision.
public class Game1 : Microsoft.Xna.Framework.Game
{
Paddle Paddle1 = new Paddle();
Paddle Paddle2 = new Paddle();
...
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
Paddle1.LoadContent();
}
...
}
class Paddle : Game1
{
...
protected override void LoadContent()
{
Paddle1 = new Vector2();
Paddle1.X = 50;
Paddle1.Y = 50;
base.LoadContent();
}
...
}
Two big problems here, there is a recursive LoadContent call. Not to mention your paddles have paddles which have paddles... Why is your paddle inheriting from Game1? It almost definitely shouldn't be.
Also your paddle instances instantiate other paddle instances, so you're in a loop of instantiating other paddle classes.
It seems like you might want to take a step back and just get used to some basic code first? For what it's worth, I wrote pong in xna for fun a few years back, it's a bit messy, but it might give you some starting help.
Here is an example of a paddle class based off the DrawableGameComponent class (drawn in primatives so it's a bit verbose):
public class Paddle : DrawableGameComponent
{
private readonly VertexPositionColor[] _vertices = new VertexPositionColor[6];
private readonly float _width;
private readonly float _height;
private IndexBuffer _indexbuffer;
private VertexBuffer _vertexbuffer;
public Vector3 Position { get; set; }
public Vector3 Direction { get; set; }
public float Speed { get; set; }
public Paddle(Game game, float width, float height)
: base(game)
{
_width = width;
_height = height;
}
protected override void LoadContent()
{
base.LoadContent();
_vertices[0].Position = new Vector3(0, 0, 0);
_vertices[0].Color = Color.Red;
_vertices[1].Position = new Vector3(_width, _height, 0);
_vertices[1].Color = Color.Green;
_vertices[2].Position = new Vector3(0, _height, 0);
_vertices[2].Color = Color.Blue;
_vertices[3].Position = new Vector3(_width, 0, 0);
_vertices[3].Color = Color.Green;
_vertexbuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), _vertices.Length, BufferUsage.WriteOnly);
_vertexbuffer.SetData(_vertices);
var indices = new short[6];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 0;
indices[4] = 3;
indices[5] = 1;
_indexbuffer = new IndexBuffer(GraphicsDevice, typeof(short), 6, BufferUsage.WriteOnly);
_indexbuffer.SetData(indices);
}
public BoundingBox GetBoundingBox()
{
return new BoundingBox(Position, Position + new Vector3(_width, _height, 0));
}
public override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
GraphicsDevice.SetVertexBuffer(_vertexbuffer);
GraphicsDevice.Indices = _indexbuffer;
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);
}
}
this is my code so far:
Game1.cs Class:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Player MyPlayer;
Texture2D Ball;
int GraphicsWidth,GraphicsHeight;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
GraphicsWidth = graphics.PreferredBackBufferWidth;
GraphicsHeight= graphics.PreferredBackBufferHeight;
MyPlayer = new Player(Ball, new Vector2(100, 100), Vector2.Zero);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
Ball = Content.Load<Texture2D>("Images/ball");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
MyPlayer.Draw(spriteBatch);
base.Draw(gameTime);
}
}
Player class(The ball):
class Player
{
Texture2D Texture;
Vector2 Positon,Velocity;
public int Height
{
get { return this.Texture.Height; }
}
public int Width
{
get { return this.Texture.Width; }
}
public Player(Texture2D tex, Vector2 position,Vector2 velocity)
{
this.Texture = tex;
this.Positon = position;
this.Velocity = velocity;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(Texture, Positon, Color.White);
spriteBatch.End();
}
}
When I try to debug the game I have the following error:
This method does not accept null for this parameter.
Parameter name: texture
In that part:
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Begin();
spriteBatch.Draw(Texture, Positon, Color.White);
spriteBatch.End();
}
Btw, I'd like to ask if I can make this code better or something like that.
Thanks alot!
Looks like you create the Player object before you've loaded the Ball content, and thus, the player holds null instead of a texture, but the Ball field in the Game is the real texture.
I would move the creation of Player into LoadContent, after you've assigned the Ball.
Ball = Content.Load<Texture2D>("Images/ball");
MyPlayer = new Player(Ball, new Vector2(100, 100), Vector2.Zero);
I'm going to preface my answer by saying you should call spriteBatch.begin() and spriteBatch.end() in your Game1.cs Draw function instead of your Player.cs Draw function. It's expensive and you shouldn't do it more than once per draw frame, unless it's absolutely necessary (it's not in this case).
With regards to your actual question, you need to load your player in the LoadContent method rather than your Initialize method.
Initialize is happening before your texture is loaded.
try moving MyPlayer = new Player(Ball, new Vector2(100, 100), Vector2.Zero);
into your LoadContent method after you load the texture into Ball.
It looks like you're loading the ball texture after you've already initialized myPlayer with the "NULL" Ball texture
This is because Initialize is called before LoadContent, and at the point you create your Player the Ball texture is still null.
Either create the Player object in LoadContent, after you load the ball, or allow Player to load its own content.