Cannot get my sprite to change direction?

I’ve been looking for so long and cannot figure out how to get my sprite to change direction, any help?


=
I cannot seem to get him to change direction when I move him left

Hard to be certain without knowing the spritesheet, I’m assuming width & height makes it 23 frames across and 4 frames down? with row 1 being walk left animation, row 2 walk right, row 3 walk up, row 4 walk down ?

If that is how the sprite sheet is layed out then you need to set the sourceRectangle’s Y position on the sprite sheet.
ie. display walking right the source rec would be (currentFrame * width, height * 2, width * 2, height * 2)

How about using this overload of SpriteBatch.Draw():
https://msdn.microsoft.com/en-us/library/ff433992.aspx

It would be something like:

var effects= SpriteEffects.FlipHorizontally; // Or SpriteEffects.None spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White, 0f, Vector2.Zero, effects, 1f);

2 Likes

Using SpriteEffects is the right approach if your sprites for walking left and right are symmetrical.

Yeah used the SpriteEffects, thanks for the help :slight_smile:

…,Height*1, …Shouldn’t it be …, Height * direction… or something like that instead of *1 ? The row to be drawn never changes, or did you hardcode it for your tests ?