views:

31

answers:

1

I'm using RotateFlip to flip sprites horizontally. It seems that RotateFlip is applied when Graphics is drawn not image.

The problem is that some sprites needs to be flipped and some not (depending on direction of sprite). I don't want to clone image each time I'm drawing flipped sprite.

+1  A: 

Consider using a transformation matrix on the Graphics object instead of using RotateFlip on the image. Flipping is equivalent to scaling the X or Y coordinates by -1. You can pre-compute a single flip matrix and use it whenever you want:

Matrix flipX = new Matrix();
flipX.Scale(-1, 1);

graphics.Transform = flipX;
// Draw your sprite here
graphics.ResetTransform();

Note however that you will have to pass in modified coordinates when drawing, for eg. using the above transform, you'll have to pass in ContainerWidth - X instead of X.

casablanca