Going over a few background details; I've been coding for a few months, I use the XNA 4.0 extension for C# Visual studio.
Now that you know all of that, here's my question;
How would I draw, say, the second line of sprites in a sprite sheet. Right now I'm just mucking around with a two line sprite sheet, one stance animation, one walking animation. I've managed to get the stance animation drawn and play through but I can't figure out how to get the walking animation drawn instead of the stance.
Here's my code;
namespace Zaru_Animated
{
class Zaru
{
public int NumOfFramesX;
public int NumOfFramesY;
public int StanceFrames;
public int WalkFrames;
public int Timer;
public int CurrentFrame;
public Vector2 ZaruPos = new Vector2 (0, 655);
public static Texture2D ZaruTexture;
public static Viewport GraphicsViewport;
public Zaru(Texture2D newTexture, Vector2 ZaruPos)
{
Timer = 0;
NumOfFramesX = 6;
NumOfFramesY = 2;
StanceFrames = 4;
WalkFrames = 6;
CurrentFrame = 0;
ZaruPos = new Vector2 (0, 0);
ZaruTexture = newTexture;
}
public void Update()
{
Timer++;
if (Timer >= 60 / 3)
{
CurrentFrame = (CurrentFrame + 1) % StanceFrames;
Timer = 0;
}
}
public void Draw (SpriteBatch spriteBatch)
{
Rectangle SourceRectangle = new Rectangle((ZaruTexture.Width / NumOfFramesX) * CurrentFrame, 0, ZaruTexture.Width / NumOfFramesX, (ZaruTexture.Height/ NumOfFramesY));
spriteBatch.Draw(ZaruTexture, ZaruPos, SourceRectangle, Color.White);
}
}
}
Sorry for the big chuck of code, I wasn't quite sure what is relevant and what isn't.
Thanks in advance.
BigBlueCloud

New Topic/Question
Reply




MultiQuote






|