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

  • Home
  • SEARCH
  • 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 3420972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:03:47+00:00 2026-05-18T06:03:47+00:00

at the moment I am developing a game in c# and im a little

  • 0

at the moment I am developing a game in c# and im a little stuck.

I need to draw the tile map. I read the tile map in using xml and store each tile in a list with its x and y position. but Im having a bit of trouble with the draw method.

     public void Draw(SpriteBatch theBatch)
     {
         int tileWidth = 32;
         int tileHeight = 32;
         int numTiles = 100;
         while (j < numTiles)
         {
             tileMap[j].Position.X *= tileWidth;
             tileMap[j].Position.Y *= tileHeight;
             theBatch.Draw(mSpriteTexture, tileMap[j].Position, Color.White);
             Console.WriteLine("tile drawn");
             Console.WriteLine("x = " + tileMap[j].Position.X);
             Console.WriteLine("y = " + tileMap[j].Position.Y);
             Console.WriteLine(" i = " + j);
             j++;
         }
    }

I thought this would work and the tile map appears on screen but then quickly disappears, any ideas what I am doing wrong? sorry if its really silly.

thanks, Iain

  • 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-05-18T06:03:47+00:00Added an answer on May 18, 2026 at 6:03 am

    Looks like the Case of the Mistranslated For Loop 🙂

    j is not declared in the method you posted, so I’m assuming it’s an instance field of type int initialised to 0. It needs to be re-initialised to 0 every time before the loop, otherwise j < numTiles will be false on every frame except the first (so the tiles will only get drawn on the first frame — since the screen is erased at the beginning of each frames, the tiles disappear if they aren’t being constantly re-drawn).

    Also, why are you multiplying the position of each tile by it’s size (on every frame, too!)? This would quickly cause the tiles to be drawn off-screen after a few frames as their positions would increase exponentially with the number of frames drawn. If the tiles aren’t moving, their positions should not need to be modified at all (and if they are moving, that should be done in the Update method, not Draw).

    Finally, make sure you comment out the Console.WriteLine calls when you’re done debugging, since writing to the console (several times per second) is rather slow.

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

Sidebar

Related Questions

I'm developing a little Game at the Moment (Android-App) and I want to save
I am developing a little game (I'm using Play! framework ). In this game,
I have been developing a game basic card game for Android. At the moment
I'm developing a small game in python. I am using a 2D rectangular grid.
I m developing app where there is list and above edit text,the moment i
At the moment I'm developing a web based application using Silverlight 3.0. For the
At the moment I'm developing using a simple editor, putty, and a VirtualBox instance
I'm developing an Android game. At the moment I'm writing code that should calculate
Frog I'm developing a flash game called Frog, at the moment my code for
I'm developing on WinXP Pro 32bit using VS2008 Pro. Do I need to create

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.