DEV Community

Cover image for XNA An Example Object using VariableService
Adam K Dean
Adam K Dean

Posted on

2 1

XNA An Example Object using VariableService

Just a quick example of how you'd lay out an object class, which you could use for items like game objects, the player object, anything that you need to update and draw independently.

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceRocks
{
    public class ExampleObject
    {
        #region Variables
        private VariableService vars;

        public Texture2D Texture { get; set; }
        public int Width { get { return Texture.Width; } }
        public int Height { get { return Texture.Height; } }

        public Vector2 Position { get; set; }
        #endregion

        #region Constructor Methods
        public ExampleObject(Game game)
        {
            vars = ServiceExtensionMethods
                .GetService<variableservice>(game.Services);
        }

        public void Initialize(Texture2D texture, Vector2 position)
        {
            Texture = texture;
            Position = position;
        }
        #endregion

        #region Update Methods
        public void Update(GameTime gameTime)
        {
            //
        }
        #endregion

        #region Draw Methods
        public void Draw(GameTime gameTime)
        {
            //
        }
        #endregion
    }
}
Enter fullscreen mode Exit fullscreen mode

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong · web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌶️🔥

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please show some love ❤️ or drop a kind note in the comments if this was helpful to you!

Got it!