Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:39:39+00:00 2026-06-02T12:39:39+00:00

I’m trying to program a game with a friend, and I’m very confused as

  • 0

I’m trying to program a game with a friend, and I’m very confused as to how to draw sprites. I can draw code in my Game1 class, below.

namespace SweetGeorgiaBrown
{
    /// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
            enum GameStates { TitleScreen, Overworld, Menu, Battle, GameOver };
    GameStates gameState = GameStates.Battle;
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Texture2D dinoTex;
    Texture2D alienTex;
    Texture2D robotTex;
    Texture2D eroboTex;
    SpriteFont basic;


    private Vector2 textLocation = new Vector2(20, 20);
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";


    }

    public class Health
    {
        public static int dinoHP = 300;
        public static int alienHP = 200;
        public static int robotHP = 100;
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here

        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);
        dinoTex = Content.Load<Texture2D>(@"Sprites\dino\dinoFrontOvwld");
        alienTex = Content.Load<Texture2D>(@"Sprites\alien\alienFrontOvwld");
        robotTex = Content.Load<Texture2D>(@"Sprites\robot\robotFrontOvwld");
        eroboTex = Content.Load<Texture2D>(@"Sprites\robo1\robo1OvwldFront");

        basic = Content.Load<SpriteFont>(@"Fonts\Basic");
        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();


        // TODO: Add your update logic here
        switch (gameState)
        {
            case GameStates.Battle:
                break;
        }
        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();

        // TODO: Add your drawing code here
        if ((gameState == GameStates.Battle))
        {
            spriteBatch.DrawString(
                basic,
                "ASDFASDFADFASDFA ", textLocation, Color.Black);
            spriteBatch.Draw(
                dinoTex, textLocation, Color.White);
        }
        spriteBatch.End();
        base.Draw(gameTime);
    }
}

}

In my Game1 code, I can successfully draw that sprite and the text there on the screen. However, I want to draw a sprite in another class, but I have absolutely no idea what to put there.

In the other class, I wish I could just do something as simple as

sprite.Draw(//here would be x and y coords of where the sprite goes, name of the texture), and have that be it, but it seems to just not work that way. Does anyone know how I can go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:39:47+00:00Added an answer on June 2, 2026 at 12:39 pm

    It does indeed work like that. Extract your sprite specific code into a class that is structured something similar to:

    public Sprite()
    {
    }
    
    public void Update(GameTime gameTime)
    {
    }
    
    public void Draw(SpriteBatch spriteBatch)
    {
    }
    

    Then in your game1 class you can call

    Sprite.Update(gameTime); 
    

    and

    Sprite.Draw(spriteBatch);
    

    That should help you get started. Did you try some approaches yourself, if so post them and we can see where they went wrong, or are you just hoping for a quick answer you can copy and paste?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.