Entwickler-Ecke

Multimedia / Grafik - Problem mit SpriteBatch


LordBen - Fr 09.04.10 15:47
Titel: Problem mit SpriteBatch
Hi leute,
seit einiger zeit beschäftige ich mich schon mit c# und nun hab ich mal noch XNA hinzugezogen
ich bin momentan dabei mir die tutorials von http://www.xnatutorials.com anzuschauen und habe (fast) alles so gemacht wie der "Macher" von diesem Tutorial.

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
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;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame3
{
    class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;
        SpriteBatch spriteBatch;
        Texture2D myTexture;
        Vector2 spritePosition;

        #region Mainmethodes

        //constructor
        public Game1()
        {
            this.graphics = new GraphicsDeviceManager(this);
            this.content = new ContentManager(this.Services);
        }

        //inizialisierung
        protected override void Initialize()
        {
            this.spritePosition = new Vector2(10050);
            base.Initialize();
        }

        //loadGraphic
        protected void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                this.myTexture = this.content.Load<Texture2D>(@"Quellen\textures\formatieren");
                this.spriteBatch = new SpriteBatch(this.graphics.GraphicsDevice);
            }
                
        }

        //unloadGraphic
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
        }

        //update
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            base.Update(gameTime);
        }

        //draw
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            this.spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            this.spriteBatch.Draw(this.myTexture, this.spritePosition, Color.White);
            this.spriteBatch.End();
            base.Draw(gameTime);
        }
        #endregion
    }
}


An markierterStelle kommt immer NullReferenceExpection nicht behandelt, was ich nicht so ganz verstehe da ich ja weiter oben bei LoadGraphicsContent einen neuen spriteBatch eingeführt habe...Kann mir vielleicht jemand helfen??


Kha - Fr 09.04.10 18:53

:welcome:

user profile iconLordBen hat folgendes geschrieben Zum zitierten Posting springen:
[...]da ich ja weiter oben bei LoadGraphicsContent einen neuen spriteBatch eingeführt habe...Kann mir vielleicht jemand helfen??
Und wo rufst du diese Methode auf?
Warum eigentlich protected? Willst du von der Klasse noch ableiten ;) ?


LordBen - Sa 10.04.10 08:35

aha...jetzt funktionierts...vielen dank...