Sonix2001

Hi everyone, another noob question I'm afraid

After creating my first XNA game (the usual...Pong ) I am now underway with my first "real project", still trying to keep it simple I thought I'd attempt to program a 'clone' of Jetpac (an old ZX spectrum classic). I'm well underway but I'm also trying to go back and improve code I've already done....anyway, to my question:

I have created my character using a png which contains different poses. At the moment it contains for example, a left facing walk and a right facing walk... I was just wondering if there was an easy way of mirroring the left walk instead of also having to add the right walk to the sprite image map.

Thanks.



Re: XNA Game Studio Express 2D Sprite Mirroring

Eli Tayrien - MSFT

I could be wrong, but isn't there an overload on SpriteBatch.Draw that lets you flip the sprites   That sounds like it would be right up your alley




Re: XNA Game Studio Express 2D Sprite Mirroring

Ecrofirt

As stated above, the quickest way to do this is with one of these overloaded Spritebatch Draw methods:
//
// Summary:
// Adds a sprite to the batch of sprites to be rendered, specifying the texture,
// destination and source rectangles, color tint, rotation, origin, effects
// and sort depth.
//
// Parameters:
// texture:
// The sprite texture.
//
// destinationRectangle:
// A rectangle specifying, in screen coordinates, where the sprite will be drawn.
// If this rectangle is not the same size as sourcerectangle the sprite will
// be scaled to fit.
//
// sourceRectangle:
// A rectangle specifying, in texels, which section of the rectangle to draw.
// Use null to draw the entire texture.
//
// color:
// The color channel modulation to use. Use Color.White for full color with
// no tinting.
//
// rotation:
// The angle in radians to rotate the sprite around the origin.
//
// origin:
// The origin of the sprite. Specify (0,0) for the upper left corner.
//
// effects:
// Rotations to apply prior to rendering.
//
// layerDepth:
// The sorting depth of the sprite, between 0 and 1.
public void Draw(Texture2D texture, Rectangle destinationRectangle, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth);


//
// Summary:
// Adds a sprite to the batch of sprites to be rendered, specifying the texture,
// screen position, optional source rectangle, color tint, rotation, origin,
// effects and sort depth.
//
// Parameters:
// texture:
// The sprite texture.
//
// position:
// The location, in screen coordinates, where the sprite will be drawn.
//
// sourceRectangle:
// A rectangle specifying, in texels, which section of the rectangle to draw.
// Use null to draw the entire texture.
//
// color:
// The color channel modulation to use. Use Color.White for full color with
// no tinting.
//
// rotation:
// The angle in radians to rotate the sprite around the origin.
//
// origin:
// The origin of the sprite. Specify (0,0) for the upper left corner.
//
// scale:
// Uniform multiple by which to scale the sprite width and height.
//
// effects:
// Rotations to apply prior to rendering.
//
// layerDepth:
// The sorting depth of the sprite, between 0 and 1.
public void Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth);


//
// Summary:
// Adds a sprite to the batch of sprites to be rendered, specifying the texture,
// screen position, source rectangle, color tint, rotation, origin, effects
// and sort depth.
//
// Parameters:
// texture:
// The sprite texture.
//
// position:
// The location, in screen coordinates, where the sprite will be drawn.
//
// sourceRectangle:
// A rectangle specifying, in texels, which section of the rectangle to draw.
// Use null to draw the entire texture.
//
// color:
// The color channel modulation to use. Use Color.White for full color with
// no tinting.
//
// rotation:
// The angle in radians to rotate the sprite around the origin.
//
// origin:
// The origin of the sprite. Specify (0,0) for the upper left corner.
//
// scale:
// Vector containing seperate scalar multiples for the X and Y axes of the sprite.
//
// effects:
// Rotations to apply prior to rendering.
//
// layerDepth:
// The sorting depth of the sprite, between 0 and 1.
public void Draw(Texture2D texture, Vector2 position, Rectangle sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);




Re: XNA Game Studio Express 2D Sprite Mirroring

Sonix2001

thanks guys,

SpriteEffects.FlipHorizontally