kinetix UK

Hi,

I am new to XNA, and programming in general, and I have been trying to figure out how to get a sprite to flip when the left key is pressed, and get the sprite to flip at the start, by using spriteBatch.Draw(..., SpriteEffects.FlipHorizontally, ...) but I am unsure what code needs to be used to make the sprite flip, once the key is pressed, after it has first been rendered. If anyone could explain how I go about this it would be much appreciated as I have been unable to find any clear descriptions of how to do this.

Thanks.


Re: XNA Game Studio Express SpriteEffects.FlipHorizontally

George Clingerman

You will want to create an object to store the current SpriteEffect for your sprite. Then when the user presses the left or right arrow, you would then set the SpriteEffect appropriately at that time.....

If you head on over to the new Microsoft forums and re-ask this question, I would be glad to give you some sample code :) How's that for incentive to use the new Microsoft forums





Re: XNA Game Studio Express SpriteEffects.FlipHorizontally

kinetix UK

Thanks, that would be greatly appreciated, I have reposted the topic here:

http://creators.xna.com/forums/810/ShowThread.aspx#810

KinetiX UK





Re: XNA Game Studio Express SpriteEffects.FlipHorizontally

kinetix UK

Thanks, that would be greatly appreciated, I have re-posted the topic here:

https://creators.xna.com/forums/thread/810.aspx

KinetiX





Re: XNA Game Studio Express SpriteEffects.FlipHorizontally

ChaosGod

If you dont want to use a class you can use the following :

Create a variable in your definition section :

SpriteEffects myEffects = SpriteEffects.None;

when you detect that the left key as been pressed, do : myEffects = SpriteEffects.FlipHorizontally;

when you detect that the right key as been pressed, do : myEffects = SpriteEffects.None;

Finally use the Draw method by replacing the SpriteEffects.FlipHorizontally byt myEffects : spriteBatch.Draw(..., myEffects, ...);

Its not what i would call a clean code, a class holding your sprite information would be much better, but for the sake of understanding the principle, it should do the trick.