Hoi ik heb een vraagje, ik krijg steeds de volgende foutmelding:The GraphicsDevice property cannot be used before Initialize has been called, maar ik zie niet waar de fout ligt. Enig idee?
dankjewel alvast
Code:
namespace Pacie
{
public class Pacman: DrawableGameComponent
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D pacmanTexture;
public Pacman(Game main, ContentManager contentManager):base(main)
{
pacmanTexture = contentManager.Load<Texture2D>("pacman");
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
public override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
// Allows the game to exit
// if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
//this.Exit();
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Draw(GameTime gameTime)
{
[COLOR="blue"]GraphicsDevice.Clear(Color.CornflowerBlue);[/COLOR] // hierbij krijg ik de foutmelding
spriteBatch.Begin();
spriteBatch.Draw(pacmanTexture,new Rectangle(0,0,40,40),Color.Blue);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
dankjewel alvast