Översikt
Detta exempel visar hur man skapar ett XNA-Studio projekt och ritar ut en texturerad rektangel med hjälp utav XNA.
Kod
Game1.cs
BoxView m_boxView; protected override void LoadContent() { m_boxView = new BoxView(GraphicsDevice, Content); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); m_boxView.drawBox(); base.Draw(gameTime); }
BoxView.cs
... namespace DrawBox { class BoxView { private SpriteBatch m_spriteBatch; private Texture2D m_boxTexture; public BoxView(GraphicsDevice graphicsDevice, ContentManager content) { m_spriteBatch = new SpriteBatch(graphicsDevice); m_boxTexture = content.Load<Texture2D>("bubbles"); } internal void drawBox() { Rectangle destrect = new Rectangle(10, 10, 20, 30); m_spriteBatch.Begin(); m_spriteBatch.Draw(m_boxTexture, destrect, Color.White); m_spriteBatch.End(); } } }