4 Replies - 2019 Views - Last Post: 03 October 2012 - 07:34 AM

#1 Nevvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-October 12

C# XNA textures turns white

Posted 02 October 2012 - 01:10 AM

Hi guys! I'm new to c#/XNA and me and my friends have just started programming a 2D shooter game in XNA.
After a while we noticed that all the textures turns white after about 1-2 min and it seems like the problem only occures on laptops (we have tried on different laptops.) I've tried to google it but found nothing of interest and we get no errors by the compiler (Microsoft Visual C# 2010 Express). We're using rectangles with Texture on them.

             {
                case GameState.MainMenu:
                    spriteBatch.Draw(Content.Load<Texture2D>("MainMenu"), new Rectangle(0,0,screen_Width, screen_Height), Color.White);
                    button_Play.Draw(spriteBatch);
                    break;

                case GameState.Playing:
                    
                    
                    spriteBatch.Draw(Content.Load<Texture2D>("bakgrund"), new Rectangle(0, 0, screen_Width, screen_Height), Color.White);
                    spriteBatch.Draw(ground, ground_rect, Color.Transparent);                                 //draws ground to the screen
                    spriteBatch.Draw(kran, kran_Rect, Color.Transparent);
                    spriteBatch.Draw(floatingPlatform, floatingPlatform_Rect, Color.Transparent);                                 //draws ground to the screen
                    spriteBatch.Draw(kranLadder, kranLadder_Rect, Color.Transparent);
                    player1.Draw(spriteBatch);                                                          //draws player1 too the screen
                    spriteBatch.Draw(pistol, pistol_Rect, Color.White);
                    spriteBatch.Draw(kranHytt, kranHytt_Rect, Color.White);
                    
                    break;
            } 


My code is bad commented at the momemt, but I hope you can understand some of it. We would greatly appreciate all information we can get about this problem.
(Excuse my english if it's bad, It's not my first language)

Is This A Good Question/Topic? 0
  • +

Replies To: C# XNA textures turns white

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 488
  • Joined: 13-June 12

Re: C# XNA textures turns white

Posted 02 October 2012 - 01:32 AM

Firstly, what method is this? How often is it called?

Everything you need to Draw should have its own Draw() method, and should be called from the game's Draw() method provided - that way, you can be sure that all textures are redrawn with each refresh. Preferably, use the same SpriteBatch and pass it to the method. That way, you can use SpriteSortMode to order sprites.

Similarly, I give each object an Update() method, called from the Game's Update() method. Logic and graphics drawing should be kept separate, or you have some messy code.
Was This Post Helpful? 0
  • +
  • -

#3 Nevvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-October 12

Re: C# XNA textures turns white

Posted 02 October 2012 - 11:41 PM

Thank you for the response. I'm currently working getting more structure to the code and comments. The code I sent in my first post is in the Draw() function (forgot to tell that, sorry) which is updated every frame, so I guess the textures are redrawn every frame, and I got my logic and graphics seperated.
I will look into the SpriteSortMode.
Once again, thanks for the response
Was This Post Helpful? 0
  • +
  • -

#4 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: C# XNA textures turns white

Posted 03 October 2012 - 06:13 AM

Why are you using Color.Transparent in your draw calls?

Besides that there is not enough code there to troubleshoot.

So you are saying the textures work correctly on a none laptop system?
Was This Post Helpful? 1
  • +
  • -

#5 Nevvb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-October 12

Re: C# XNA textures turns white

Posted 03 October 2012 - 07:34 AM

View Postbonyjoe, on 03 October 2012 - 06:13 AM, said:

Why are you using Color.Transparent in your draw calls?

Besides that there is not enough code there to troubleshoot.

So you are saying the textures work correctly on a none laptop system?


I'm using Color.Transparent to make a collider without showing a texture(it is temporary while testing the physics).

Yes, this problem has only occured on laptop systems so far, but as we were "cleaning" the code and added health to the character, the problem somehow got solved (would have been nice to know why, but we can't find reason for the problem/fix)

So I guess I don't need help anymore (but thanks for giving me the response u could), but if you want to try to actually find the problem, I can give you more relative code.

Thanks for the help (this is my first real project in programming, and first time in C#/XNA, so sorry for giving you bad information about the problem)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1