3
votes

I have a source image which contains lots of pictures in a line of a guy in various stages of animation. I loaded paint and found the first man starts at 16 pixels across and 0 down, and has a width of 16 pixels and a height of 16 pixels (There is a black space on the left of the image)

So in my XNA code, I set the source rectangle to 16, 0, 16, 16 and draw it to the screen. However I just get a black square. If i increase the rectangle size hugely I get part of my image, but it seems like pixels and 'texels' are not 1 to 1.

I have tried googling about them but I can't find anything helpful at all. How do I display a simple graphic like this? This is my first XNA attempt.

5

5 Answers

1
votes

Hi Simon,
nice to see someone showing interest into XNA.
I highly recommend www.riemers.net. It is an site with extremely well written and easy to understand tutorials on XNA.

1
votes

Maybe you should try follow some tutorials instead, like other posters mentions here. For instance I can recommend The 2D shooter tutorial at riemers.net, which shows you a lot of the basics for creating an XNA game.

Some of these threads on SO might also get you on the right track:

0
votes

I suggest you look at the XNA Platformer Starter Kit included with XNA 3.1. This sample also uses sprite animations the way you describe.

Also, there are many samples at XNA Creators Club that targets 2D graphics techniques, e.g. the Sprite Sheet sample.

0
votes

From what you describe, it should display correctly. I'd need to see the source code and the image file used to diagnose the issue.

0
votes

XNA Debug Terminal is an option for quickly debugging your games. It is an open source library you can setup in seconds that allows you to see the value of any variable, invoke any method, watch values changing in real-time, and more by simply typing c# code into a terminal-like display that appears atop your game window. Unlike the normal Visual Studio debugger, you can invoke arbitrary code while your game is running. You can find out more about this at http://www.protohacks.net/xna_debug_terminal . This will greatly help you to avoid a lot of frustration while learning XNA.