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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:30:55+00:00 2026-06-11T22:30:55+00:00

Instead of creating separate cases for each tile, what would a better way of

  • 0

Instead of creating separate cases for each tile, what would a better way of doing this be?

public void Draw(SpriteBatch spriteBatch, Level level)
    {
        for (int row = 0; row < level._intMap.GetLength(1); row++) {
            for (int col = 0; col < level._intMap.GetLength(0); col++) {
                switch (level._intMap[col, row]) {
                    case 0:
                        spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(0 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
                        break;
                    case 1:
                        spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(1 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
                        break;
                    case 2:
                        spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(2 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
                        break;
                    case 3:
                        spriteBatch.Draw(_texture, new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), new Rectangle(3 * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White);
                        break;

                }
            }
        }
    }
  • 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-11T22:30:56+00:00Added an answer on June 11, 2026 at 10:30 pm

    There’s no need for the case statement, just use a variable.

    var n = level._intMap[col, row];
    spriteBatch.Draw(_texture, 
        new Rectangle(row * _tileWidth, col * _tileHeight, _tileWidth, _tileHeight), 
        new Rectangle(n * _tileWidth, 0 * _tileHeight, _tileWidth, _tileHeight), Color.White
    );
    

    If you need to restrict the output to value 0-3 (as is the effect of the case statement), then best to use a conditional if (n >= 0 && n <= 3) { }.

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

Sidebar

Related Questions

Instead of creating separate questions for each, here's a list of XCode 4 related
Why is this creating a new row at the bottom with this data instead
ThreadPool keeps thread idle instead of creating and tearing them down, not all the
is it possible to insert an object into a session instead of creating a
I have a set of tasks that are done repeatedly and instead of creating
Instead of having nested callbacks in JS, I would like to fire and listen
In MbUnit one can do something like this: [Test] [TestCategory(Bad Arguments)] [TestCategory(Fast)] [ExpectedException(typeof(ArgumentNullException))] public
I'm trying to find a better way in expressing my cucumbers so I am
Can we get highlighter to replace original document field instead of creating new segment
I tried to create a new folder following the instructions at https://developers.google.com/google-apps/documents-list/#creating_a_new_document_or_file_with_metadata_only instead of

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.