XNA Sprite Sheets

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
epicasian
Chaos Rift Junior
Chaos Rift Junior
Posts: 232
Joined: Mon Feb 22, 2010 10:32 pm
Current Project: Gigazilla Engine
Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
Programming Language of Choice: C/++
Location: WoFo, KY

XNA Sprite Sheets

Post by epicasian »

Can someone point me in the right direction for a simple tutorial?

Thanks,
EpicAsian
User avatar
davidthefat
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 529
Joined: Mon Nov 10, 2008 3:51 pm
Current Project: Fully Autonomous Robot
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: California
Contact:

Re: XNA Sprite Sheets

Post by davidthefat »

http://creators.xna.com/en-US/sample/spritesheet
There are tons of tutorials on this site, which is owned and operated by microsoft, its their main XNA site
User avatar
epicasian
Chaos Rift Junior
Chaos Rift Junior
Posts: 232
Joined: Mon Feb 22, 2010 10:32 pm
Current Project: Gigazilla Engine
Favorite Gaming Platforms: Dreamcast, SNES, PS2, PC
Programming Language of Choice: C/++
Location: WoFo, KY

Re: XNA Sprite Sheets

Post by epicasian »

I've looked at that, I guess I was to aggravated to actually sit down and look at all the code.

Thanks,
EpicAsian

Edit:
So, in XNA, The sprite sheets are just a lot of different, single image files?

I'm used to loading in one file with many sprites on it (SDL).

~EpicAsian
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: XNA Sprite Sheets

Post by mattheweston »

You basically have one image with many sprites on it(Spritesheet). From there you have to locate within the spritesheet the individual sprite you want to draw.

First you add the spritesheet image to your project.
You then load the spritesheet into a 2D texture.
Then you can setup rectangles for the individual sprites you need.
Finally you use the rectangles that you created in your calls to the draw function.


This is at least what I've learned so far in my study of XNA.
Image
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: XNA Sprite Sheets

Post by MrDeathNote »

mattheweston wrote:You basically have one image with many sprites on it(Spritesheet). From there you have to locate within the spritesheet the individual sprite you want to draw.

First you add the spritesheet image to your project.
You then load the spritesheet into a 2D texture.
Then you can setup rectangles for the individual sprites you need.
Finally you use the rectangles that you created in your calls to the draw function.


This is at least what I've learned so far in my study of XNA.
^This is the basic idea of it. I'll try go into a bit more detail:

Code: Select all

                spritebatch.Draw(texture,
                position,
                new Rectangle(currentFrame.X * frameSize.X,
                    currentFrame.Y * frameSize.Y,
                    frameSize.X, frameSize.Y),
                Color.White, 0, Vector2.Zero,
                1f, SpriteEffects.None, 0);
the section you should be concerned with is the third parameter.

Code: Select all

                new Rectangle(currentFrame.X * frameSize.X,
                    currentFrame.Y * frameSize.Y,
                    frameSize.X, frameSize.Y),
This finds the current frame in the tilesheet. You need two Vector2's currentFrame(to hold the position of the frame on the tilesheet eg 0,0 is the first frame starting at the top left corner) and frameSize(which holds the size of each frame eg if the sheet was full of 32x32pixel tiles then frameSize would hold 32, 32).
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
Post Reply