Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the tutorial on Spritebatch Basics. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |


Hi there, im a bit confused about the part called:
"Create a Place to Store the Images In Game"
where should i put these "private.. " stuff?
Thanks
The "private Texture2D …" lines get placed into the Game1.cs file just AFTER the lines:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
… //«right here!
.
.
.
//rest of the class is down here…
}
spriteBatch in XNA 3. could be used for 3D. spriteBatch.Begin(…SaveStateMode.SaveState …..). In XNA 4. parameter does not exit.
What do do?
I think that's discussed over in the 2D/3D Combined tutorial. Let me know if that doesn't do it for you.
hai thar, when i create an image it still has that square around it and when i use it in the program the white square is shown around this image, unlike your arrow and other images.
try: spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
instead of: spriteBatch.Begin();
I'm using XNA3 on C# 2008 Express and Windows XP. My spritebatch window has a cornflowerblue rectangle beneath the stars background sprite, as if the image is not deep enough to entirely cover the whole window, or the default window size is higher than 480 pixels. Is there a way of setting the size of this window to 800x480?
"We've put the earth sprite at 400, 300, which is the center of the screen "
First of all, you didn't put the earth sprite at 400, 300.
Second, 400, 300 is not the center of the screen :)
It used to be! The default window size used to be 800x600. Now it's 800x480, which is the size of the Windows 7 Phone. So it's a resolution that works well on all intended targets for XNA. Honestly, I wish the default were 1280x720, since I've never paid too much attention to the Windows 7 Phone. I'm always having to change it bigger.
I've fixed this now, I think. (But I fully expect you to tell me if it's not!) :D
Well, of course I won't let you down :) The code is fixed, but now the image doesn't correspond …
No sorry, just kidding. But I do remember when I first started programming, and read lots of tutorials all over the net, even the smallest mistake in code and/or explanation can be very annoying. I spent lots of time wondering why my results were different than what the tutorial said they had to be. Eventually, this would make me searching for other (better) tutorials, and I don't think that's what the writer had in mind …
So if you don't mind, I'll keep on reporting small errors ;)
I actually wondered about the image myself. I was going to double check it tonight when I don't have to do everything through my phone.
PLEASE keep reporting these small errors. You've been keeping me busy the last little bit with these small problems, but I agree completely; it makes a world of difference to the people going through these tutorials!
Time to go to bed now, but tomorrow I'll probably give you some work to do ;-)
Cheers!
Hi RB,
First of all, let me thank you for such a nice website :)
Let me inform you that I have started reading your tutorial regarding XNA 4.0 and there were parts where you write that something has been already overview or explained, but taking in consideration that I have been reading the tutorials in order and not going to the links with more explanation about other topics, people might get a little bit lost, let me quote you some text from this topic:
"We already mentioned what spriteBatch.Begin() and spriteBatch.End() do", being honest I would suppose what are those methods' job, I would say that they start the drawing "session" and when you call the End function what ever was inside those two lines of code will be taken in consideration while drawing in the screen.
I would like to suggest you the use of some tooltip, those small clouds that appear near the mouse when it is hovering a specific word.
Cheers,
Elqno
Hi, back again, and I've run into a wall (sorta). I want to remove a sprite at command (using a key) then replace it with a new one. how exactly do I tell the game to remove the sprite without crashing? I basically first just want the player to disappear, then the next step would be to replace it with a new one.
I can't use Texture Atlas' or Sprite Sheets because the game is a Top Down Shooter, and I'm unsure how a spritesheet would affect player rotation.