Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:14:26+00:00 2026-06-17T21:14:26+00:00

I am writing a simple game based on grid movements, something like Sokoban game.

  • 0

I am writing a simple game based on grid movements, something like Sokoban game. I need to use several different text files to store levels. I wrote some code, and now I get error:

System.ArgumentNullException “This method does not accept null for
this parameter. Nazwa parametru: texture”

Whole code is in several files. What is wrong with my code?

Game1.cs

using System;
using System.Collections.Generic;
using System.IO;
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 Sokoban
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Texture2D tOtoczenie;
        public Rectangle kOtoczenie;

        Sceny scena;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = 660; // 11
            graphics.PreferredBackBufferWidth = 900; // 15
            Content.RootDirectory = "Content";
        }

        // Sterowanie po gridzie (en - grid movement with stops)
        KeyboardState stanKlawiatury, poprzedniStanKlawiatury;

        public bool WcisnietyKlawisz(Keys klawisz)
        {
            return stanKlawiatury.IsKeyDown(klawisz) && poprzedniStanKlawiatury.IsKeyUp(klawisz);
        }

        /// <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>
        /// 

        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            scena = new Sceny();

            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);

            // TODO: use this.Content to load your game content here
            tOtoczenie = Content.Load<Texture2D>("Otoczenie");
            kOtoczenie = new Rectangle(0, 0, 900, 660);
        }

        /// <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>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            poprzedniStanKlawiatury = stanKlawiatury;
            stanKlawiatury = Keyboard.GetState();

            if (WcisnietyKlawisz(Keys.Right))
                scena.wspX += 60;

            else if (WcisnietyKlawisz(Keys.Left))
                scena.wspX -= 60;

            else if (WcisnietyKlawisz(Keys.Up))
                scena.wspY -= 60;

            else if (WcisnietyKlawisz(Keys.Down))
                scena.wspY += 60;

            if (Keyboard.GetState().IsKeyDown(Keys.NumPad1))
                scena.LoadScene("level1");

            scena.Update();
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();
            spriteBatch.Draw(tOtoczenie, kOtoczenie, Color.White);
            spriteBatch.End();
            scena.Draw(spriteBatch);

            base.Draw(gameTime);
        }
    }
}

Sceny.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Microsoft.Xna.Framework.Content;

namespace Sokoban
{
    public class Sceny
    {
        public List<ObiektyGry> sciany;
        public List<ObiektyGry> sloty;
        public List<ObiektyGry> diamenty;
        public List<ObiektyGry> graczL;

        public Texture2D tDiament;
        public Texture2D tSlot;
        public Texture2D tSciana;

        public Rectangle kDiament;
        public Rectangle kSlot;
        public Rectangle kSciana;

        public Texture2D tGracz;
        public Rectangle kGracz;

        public int wspX;
        public int wspY;

        public Sceny()
        {
            sciany = new List<ObiektyGry>();
            sloty = new List<ObiektyGry>();
            diamenty = new List<ObiektyGry>();
            graczL = new List<ObiektyGry>();
        }

        public void LoadContent(ContentManager theContentManager, string theAssetName)
        {
            tGracz = theContentManager.Load<Texture2D>("Gracz");
            tDiament = theContentManager.Load<Texture2D>("Diament");
            tSlot = theContentManager.Load<Texture2D>("Slot");
            tSciana = theContentManager.Load<Texture2D>("Ściana");
        }

        public void Update()
        {
            foreach (ObiektyGry obiekt in sciany)
                obiekt.Update();
            foreach (ObiektyGry obiekt in sloty)
                obiekt.Update();
            foreach (ObiektyGry obiekt in diamenty)
                obiekt.Update();
            foreach (ObiektyGry obiekt in graczL)
                obiekt.Update();
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            foreach (ObiektyGry obiekt in sciany)
                obiekt.Draw(spriteBatch, obiekt.Tekstura, obiekt.Kształt);
            foreach (ObiektyGry obiekt in sloty)
                obiekt.Draw(spriteBatch, obiekt.Tekstura, obiekt.Kształt);
            foreach (ObiektyGry obiekt in diamenty)
                obiekt.Draw(spriteBatch, obiekt.Tekstura, obiekt.Kształt);
            foreach (ObiektyGry obiekt in graczL)
                obiekt.Draw(spriteBatch, obiekt.Tekstura, obiekt.Kształt);
        }

        public void LoadScene(string name)
        {
            sciany.Clear();
            graczL.Clear();
            diamenty.Clear();
            sloty.Clear();

            StreamReader reader = new StreamReader(name+".txt");

            int x = 0;
            int y = 0;

            string file = reader.ReadToEnd();

            for (int i = 0; i<file.Length; i++)
            {
                if (file[i] == 13)
                {
                    y++;
                    x = 0;
                }
                else if (file[i] != 10)
                    x++;

                if (file[i] == '1' ) // sciana
                {
                    ObiektyGry sciana = new ObiektyGry();
                    sciana.Kształt = new Rectangle(x * 60, y * 60,60,60);
                    sciana.Tekstura = tSciana;
                    sciany.Add(sciana);
                }

                else if (file[i] == '2') // slot
                {
                    ObiektyGry slot = new ObiektyGry();
                    slot.Kształt = new Rectangle(x * 60, y * 60, 60, 60);
                    slot.Tekstura = tSlot;
                    sloty.Add(slot);
                }

                else if (file[i] == '3') // diament
                {
                    ObiektyGry diament = new ObiektyGry();
                    diament.Kształt = new Rectangle(x * 60, y * 60, 60, 60);
                    diament.Tekstura = tDiament;
                    diamenty.Add(diament);
                }

                else if (file[i] == '4') //gracz
                {
                    ObiektyGry gracz = new ObiektyGry();
                    wspX = x * 60;
                    wspY = y * 60;
                    gracz.Kształt = new Rectangle(wspX, wspY, 60, 60);
                    gracz.Tekstura = tGracz;
                    graczL.Add(gracz);
                }
            }
        }
    }
}

ObiektyGry.cs

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 Sokoban
{

    public class ObiektyGry
    {
        public Rectangle Kształt { get; internal set; }
        public Texture2D Tekstura { get; internal set; }
        public static ContentManager contentManager;

        public ObiektyGry()
        {

        }


        public void Update()
        {

        }

        public void Draw(SpriteBatch spriteBatch, Texture2D Tekstura, Rectangle Ksztalt)
        {
            //Tekstura = obiekt.Tekstura;
            //Kształt = obiekt.Kształt;

            //spriteBatch.Begin();
            spriteBatch.Draw(Tekstura, Ksztalt, Color.White);
            //spriteBatch.End();
        }
    }
}

level1.txt (for example)

111111111111111
100000000000001
100000000000001
100000000000001
100020000000001
100000034000001
100000000000001
100000000000001
100000000000001
100000000000001
111111111111111
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:14:28+00:00Added an answer on June 17, 2026 at 9:14 pm

    So, I deleted all Sceny class and I implemented level changing in Game1 class. After that I hadn’t any problem with textures at all!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm tinkering with writing a simple text-based role-playing game. I would like to use
I'm writing a small text-based game for my class. The navigation is simple, in
I'm writing a code for a simple text based game, and when I purchase
I am writing a simple java console game. I use the scanner to read
I'm writing a simple game - snake. I would like to have background and
I'm writing a simple card game in JavaScript, and I'd like to have a
I'm writing a simple Java 2D game, displaying a grid. The grid is (for
I'm writing a MUD (text based game) at the moment using java. One of
I'm writing a simple game with python, pygame and py2app. (I use python 2.6)
I'm writing a simple game, and thought it would be much easier to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.