Skip to content

Instantly share code, notes, and snippets.

@kenpower
Created September 26, 2013 09:31
Show Gist options
  • Select an option

  • Save kenpower/6711917 to your computer and use it in GitHub Desktop.

Select an option

Save kenpower/6711917 to your computer and use it in GitHub Desktop.
Using a matrix to position a sprite in XNA
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
rotation -= 0.03f;
Vector2 origin = new Vector2(invader.Width / 2, invader.Height / 2);
//spin in place
Matrix alienTransform =
Matrix.CreateRotationZ(rotation) *
Matrix.CreateTranslation(200, 200, 0);
spriteBatch.Begin(SpriteSortMode.BackToFront,
null, null, null, null, null,
alienTransform);
spriteBatch.Draw(invader, //texture2D
Vector2.Zero, //position
null,Color.White, 0,
origin,//
1, SpriteEffects.None, 0);
spriteBatch.End();
base.Draw(gameTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment