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 8616249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:34:23+00:00 2026-06-12T05:34:23+00:00

I’m triyng to make an Automated type tile system to draw my int[,] tileMap

  • 0

I’m triyng to make an Automated type tile system to draw my int[,] tileMap according to my Texture Atlas but when i run the code i get the entire thing sideways and the textures don’t appear, the only way i know it’s sideways is because the “Color color” for drawing the textures are different then the ClearScreen’s color.

Tile Sorting Class:

    public Texture2D Texture { get; set; }
    public int Rows { get; set; }
    public int Columns { get; set; }
    public int totalTiles;
    public int _tileWidth;
    public int _tileHeight;
    public int[] tiles;
    public int[,] tileMap = new int[,] {
            {0,0,0,0,0,0,2,0,0,0,},
            {0,0,0,0,0,2,2,0,0,0,},
            {0,0,0,0,0,2,0,0,0,0,},
            {0,0,0,0,0,2,0,0,0,0,},
            {0,0,0,2,2,2,0,0,0,0,},
            {0,0,0,2,0,0,0,0,0,0,},
            {0,0,0,2,0,0,0,0,0,0,},
            {0,0,2,2,0,0,0,0,0,0,},
            {0,0,2,0,0,0,0,0,0,0,},
            {0,0,2,0,0,0,0,0,0,0,}
    };

    public Tile(Texture2D texture, int tileWidth, int tileHeight)
    {
        _tileWidth = tileWidth;
        _tileHeight = tileHeight;
        Texture = texture;
        totalTiles = Rows * Columns;

    }


    public void Update() {

    }

    public void Draw(SpriteBatch spriteBatch, Vector2 location)
    {

        for (int row = 0; row < tileMap.GetLength(1); row++) {

            for (int col = 0; col < tileMap.GetLength(0); col++) {

                switch (tileMap[row, col]) {
                    case 0:
                        spriteBatch.Draw(Texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(1 * _tileWidth, 1 * _tileHeight, _tileWidth, _tileHeight), Color.Transparent);
                        break;
                    case 2:
                        spriteBatch.Draw(Texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(2 * _tileWidth, 2 * _tileHeight, _tileWidth, _tileHeight), Color.Transparent);
                        break;
                    default:
                        break;
                }

            }

The Main Class

public class Main : Microsoft.Xna.Framework.Game {
    // Basic code for drawing.
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Tile test;
    Texture2D texturePack;

    public Main() {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }


    protected override void Initialize() {

        base.Initialize();
    }


    protected override void LoadContent() {
        spriteBatch = new SpriteBatch(GraphicsDevice);

        texturePack = Content.Load<Texture2D>("AxiomTileSheet");
        test = new Tile(texturePack, 8, 8);
    }


    protected override void UnloadContent() {
    }


    protected override void Update(GameTime gameTime) {

        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            this.Exit();


        base.Update(gameTime);
    }


    protected override void Draw(GameTime gameTime) {
        GraphicsDevice.Clear(Color.White);

        spriteBatch.Begin();
        test.Draw(spriteBatch);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}
  • 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-12T05:34:24+00:00Added an answer on June 12, 2026 at 5:34 am

    this

    switch (tileMap[row, col]) 
    

    should be

    switch (tileMap[col, row])
    

    as you use col for you x values and row for y.

    You also need to switch this in your rectangle calculations.

    Another hint for performance based on my experience (as Andrew mentioned this may not be worthwhile in every case) instead of creating new rectangles every frame define 2 rectangles in you Tile class and just change the x and y values every frame

    floAr

    EDIT: Color Problem=============================

    You can completly get rid of the switch case construct by using

    public void Draw(SpriteBatch spriteBatch)
            {
        for (int row = 0; row < tileMap.GetLength(1); row++) {
            for (int col = 0; col < tileMap.GetLength(0); col++)
                {
                            spriteBatch.Draw(_texture, new Rectangle(row * _tW, col * _tH, _tW, _tH), new Rectangle(tileMap[row, col] * _tW, tileMap[row, col] * _tH, _tW, _tH), Color.White);
                }
            }
            }
    

    Note: _tH=_tileHeight, _tW=_tileWidth
    I tested this out and it worked like a charm for me 😉
    If you want to keep the switch case make sure you set Color.White as your tinting color (last spritebatch parameter). And you need to correct the values of the switch case, as you use 0 and 2 in your map definition, but 0 and 1 in your switch case. Expanding the cases up to 3 (as it seems you have 4 tiles by now) also worked for me.

    So I think your issue was based on the wrong color and a typo in the case structure.

    Hope this helps 🙂

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.