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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:55:39+00:00 2026-05-27T04:55:39+00:00

The scenario I am working on a HUD class to aid me in development

  • 0

The scenario

I am working on a HUD class to aid me in development of an OpenGL project. I want to be able to add new elements onto the screen dynamically (positioning will happen automatically) with the use of an add_element(char*, float) method. Here is the said code:

class HUD {
public:
    HUD();
    ~HUD();
private:
    int elements,
        spacing;
public:
    void add_element(char*, float);
};

HUD::HUD() : elements(0), spacing(10) {}
HUD::~HUD() {}

void HUD::add_element(char* string, float value) {

    ++elements;
    // .. render to screen .. //
}

The basic idea is: It will position them vertically for me as I continue to add elements.

The problem

The class gets instantiated inside the main function, and the elements get added and drawn to the screen within and at the end of my game loop. This means, every frame, the element counter gets incremented, when it should only increment the first time a unique element is added. I have thought about adding unique identifiers as an argument, like numbering them manually every time I call the method, but this seems to defeat the purpose I am going for.

I am just looking for some ideas that can solve this type of incrementing inside a loop. I have a few scenarios in which I need to do this, and the HUD is the first one I ran into.

  • 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-27T04:55:40+00:00Added an answer on May 27, 2026 at 4:55 am

    I did a similar thing working on an XNA game (so C#). My class had a list of things to be written on screen:

    struct to_write {
        string text;
        Vector2 position;    // X and Y coords relative to the screen
    }
    
    private List<to_write> _logs;
    

    I did a “write” function which adds a new to_write element to the _logs list

    void Write(string txt, Vector2 pos)
    {
        _logs.AddLast(new to_Write() { text = txt, position = pos });
    }
    

    but the actual output on screen happened only during the draw function:

    foreach(to_write w in _logs)
        // write w.text at coordinates w.position.x and w.position.y
    
    _logs.Clear();
    

    This class’s Update() and Draw() methods were the last that were called allowing every other component to add its own informations to the HUD. You can make things simpler by using a simple array and keeping an array pointer, this way both adding element to write and clearing the list are O(1).

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

Sidebar

Related Questions

Scenario: I am working on a Android project where in one particular openGL page,
Scenario: I'm working on a web services project. It supports SOAP and REST. The
Scenario: 2 developers working on the same project (VS2010, C#, MVC3, WinXP) on seperate
I'm new to RX, and I have my desired scenario working well, but it
This is the scenario: I'm working on a new ASP.NET application that uses master
Hi Scenario I'm working on is similar to twitter. What I want to do
Scenario : I am working on LOB application, as in silverlight every call to
Here's my scenario - I am working with SL3 (and WCF Data Services) and
I am working on a tests scenario that downloads a file from a website
Scenario: My installation of SQL Server 2008 Web Edition SP1 was working properly. Since

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.