Author |
Message |
4sak3nX
|
Posted: Tue May 22, 2012 9:09 pm Post subject: XNA sprite animation question |
|
|
not sure if this is the place to post this, or if there even is a place to put it but I think this is the best thread.
Basically I have a sprite as seen here: http://dl.dropbox.com/u/9328583/dawn.png
I was able to get it to draw the first frame but cant get it to animate. I cant seem to figure out why. If anyone can link me to some code that will make it work, or give me some advice that would be great. Im pretty new to this, so go easy! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Tue May 22, 2012 9:56 pm Post subject: RE:XNA sprite animation question |
|
|
Maybe you should split it into seperate images first. Did you do that already? |
|
|
|
|
|
mirhagk
|
Posted: Wed May 23, 2012 8:17 am Post subject: RE:XNA sprite animation question |
|
|
Actually Raknarg it's not a good idea to split it up first. If this was Turing that might be true, but XNA uses the graphics card, and it's better to have one big image stored on the graphics card than to keep switching between smaller ones (in most cases). That's the reason spritesheets exist, and why games like minecraft have all the tiles all on one giant image (with that minecraft can draw all the tiles with passing only a single image) |
|
|
|
|
|
Raknarg
|
Posted: Wed May 23, 2012 8:25 am Post subject: RE:XNA sprite animation question |
|
|
Oh I just looked at the section and assumed he was using VB.
So what, you just define the area of the image you want to be used? |
|
|
|
|
|
mirhagk
|
Posted: Wed May 23, 2012 8:41 am Post subject: RE:XNA sprite animation question |
|
|
Yes, I am currently not on a computer where I can code a solution, but later today I will post some code that will animate that. If you want I can help you write an animation class that will take a picture as above, with some parameters, and then it will automatically animate it. |
|
|
|
|
|
4sak3nX
|
Posted: Wed May 23, 2012 3:45 pm Post subject: RE:XNA sprite animation question |
|
|
the idea of the class sounds great! Id love to have that if you could.
As for the issue, I figured it out after a few hours of bashing my head into a table. If anyone is interested I can post my final code and such. |
|
|
|
|
|
Raknarg
|
Posted: Wed May 23, 2012 5:08 pm Post subject: RE:XNA sprite animation question |
|
|
do it |
|
|
|
|
|
jr5000pwp
|
Posted: Wed May 23, 2012 7:33 pm Post subject: RE:XNA sprite animation question |
|
|
Working with sprites is super simple in XNA. There is a sourceRectangle and a destinationRectangle. The sourceRectangle represents what part of the image you are using, and the destinationRectangle represents where on the screen the image will go. Using a spriteWidth and animationStage variable, you can neatly and cleanly animate the image. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
mirhagk
|
Posted: Thu May 24, 2012 8:03 am Post subject: RE:XNA sprite animation question |
|
|
jr5000pwp is right, you just get the width of a single frame, and times it by what frame your in, and that's the x coordinates for the source rectangle.
if your sprite is something like:
0123456
then your rectangle will be
sourceRect = new Rectangle(0,currentState*width,height,(currentState+1)*width);
Basically the class is just abstracting that away so you just have to call getSourceRect() and it will return the source rectangle. |
|
|
|
|
|
|