Created
September 26, 2013 09:31
-
-
Save kenpower/6711917 to your computer and use it in GitHub Desktop.
Using a matrix to position a sprite in XNA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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