Game Development Community

Trying to update a HUD

by Arden · in Torque X 2D · 09/23/2010 (3:25 pm) · 3 replies

I created an object within Game.cs, named _playGui, inheriting from the class GuiPlay : GUISceneview, IGUIScreen like this:

GuiPlay _playGui = new GuiPlay();
GUICanvas.Instance.SetContentControl(_playGui);

Now, what I want to do is to create a use this as an instance I can use through the code so I can update the HUD with scores and such.

So I have added:
public GuiPlay Instance
        {
            get { return _instance;}
        }
and:
#region Private, protected, internal fields
        private static GuiPlay _instance;

But when I compile, I am getting the error:

Inconsistent accessibility: property type 'StarterGame2D.GuiPlay' is less accessible than property 'StarterGame2D.Game.Instance'

Is there a way to fix this, or do you guys thing I'm going at it the wrong way (my intent being having HID scene objects associated with individual GUI components that then can be easily moved around in the editor).

Thanks!

#1
09/23/2010 (4:35 pm)
Accessibility error is usually due to some variable not being made public. The concept of a GUI element that is set by scene loading is something I also explore, and use, so I can say it can be done easily enough.
#2
09/23/2010 (5:57 pm)
I am not sure the error originates from the code you have shown us...

If I understand what you want to do, GuiPlay becomes a Singleton, right?

In that case, Instance must be static as well if you want to call it this way:

GuiPlay.Instance.doSomething();

Is this the issue?


#3
09/23/2010 (8:00 pm)
Must have. However I decided to go about it another way, by restricting the Guiplay instance to Games.cs and working directly from the GuiPlay class which creates HUD objects from other GUIControl custom classes the first time it is called.

Works well so far.

Thanks for the answer though!