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 6201949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:38:41+00:00 2026-05-24T04:38:41+00:00

I am trying to developing p a JRPG/dungeon crawler as a summer project and

  • 0

I am trying to developing p a JRPG/dungeon crawler as a summer project and I am atm cleaning up in my code. In the combat it exists “healthbars” and one healthbar consists of 3 rectangles that need to be drawn for each character (2-8 characters in total depending on the context means up to 24 healbar rectangles at one time).

My old way to draw the healbar was based on 1 texture where i took a single pixel from
and draw over a rectangle shaped area. Basicly i used the “HealtBar” texture as a color palet… for example if the source rectangle was (0, 0, 1, 1) it represented to draw a black rectangle.

Texture2D mHealthBar;
mHealthBar = theContentManager.Load<Texture2D>("HealthBar");

public override void Draw(SpriteBatch theSpriteBatch)
        {
            //draw healtbar
            theSpriteBatch.Draw(mHealthBar, new Rectangle((int)Position.X+5,
            (int)(Position.Y - 20), (MaxHealth * 5)+7, 15),
            new Rectangle(0, 0, 1, 1), Color.Black);

            theSpriteBatch.Draw(mHealthBar, new Rectangle((int)(Position.X + 8),
            (int)(Position.Y - 17), ((MaxHealth * 5)), (mHealthBar.Height) - 2),
            new Rectangle(2, 2, 1, 1), Color.White);

            theSpriteBatch.Draw(mHealthBar, new Rectangle((int)(Position.X + 8),
            (int)(Position.Y - 17), ((Health * 5)), (mHealthBar.Height) - 2),
            new Rectangle(3, 2, 1, 1), Color.Red);
      }

this aint a good looking solution… so instead i tried to create an abstract class that would reduce the amount of code and increase the amount of clarity in the code.

abstract class Drawer
{
    static private Texture2D _empty_texture;

    static public void DrawRect(SpriteBatch batch, Color color, Rectangle rect)
    {
        _empty_texture = new Texture2D(batch.GraphicsDevice, 1, 1);
        _empty_texture.SetData(new[] { Color.White });

        batch.Draw(_empty_texture, rect, color);
    }
}

With the new Drawer class I could throw away the “mHealthBar” variable and draw the rectangles in a more nice looking code way. But when I started to use the new way to draw the game started to have frame Rate problems, the old way was smooth…what is the reason to the frame rate problems?

        Drawer.DrawRect(theSpriteBatch, Color.Black, new Rectangle((int)Position.X+5,
        (int)(Position.Y - 20), (MaxHealth * 5)+7, 15));

        Drawer.DrawRect(theSpriteBatch, Color.White, new Rectangle((int)(Position.X + 8),
        (int)(Position.Y - 17), (MaxHealth * 5), 9));

        Drawer.DrawRect(theSpriteBatch, Color.Red, new Rectangle((int)(Position.X + 8),
        (int)(Position.Y - 17), (Health * 5), 9));
  • 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-05-24T04:38:42+00:00Added an answer on May 24, 2026 at 4:38 am

    The issue is that you’re creating a new texture and setting the colour every time you want to draw.

    What you should do is only create the texture once (when loading your other content).

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

Sidebar

Related Questions

One of the patterns that I frequently run across when developing is trying to
Developing server side code i finally got my eyes X-crossed trying to write -
I am developing a small web app project (ColdFusion) and I am trying to
I am currently developing a game and I'm trying to use one AnimationDrawable to
so I'm trying my hand at android developing this summer. I was trying to
I am developing an SSRS 2008 report and am trying to get one of
I'm developing (or trying to develop) a project in C# which stores data in
Developing a website and just trying to get back into the swing of (clever)
I was developing a small function when trying to run an enumerator across a
I am trying to get started developing using the .NET Micro Framework but appear

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.