0

So I recently accepted the challange of programming a simple top down style rpg in a week. Progress was going well until I decided to add a custom GUI. Its all very simple for the moment, but I have run into a little bit of a pickle...

I have a base class 'Button.cs', which is called upto everytime I need to add a button to the game. It looks a little like this:

public Button(ContentManager content, SpriteBatch spriteBatch, Type type, int x, int y, int width, int height, string texture, string name, params string[] message)

Where 'type' defines whether the button is a button, or just a clickable string.=, and 'Message' is just the strings displayed if the type == string.

I also added an 'OnClick' method to deterin if the button has been clicked:

public bool BttnOnClick(Cursor cursor)
{
    if(button.Contains(cursor.mouseRect.X, cursor.mouseRect.Y))
    {
        MouseState mNewState = Mouse.GetState();

        if(mNewState.LeftButton == ButtonState.Pressed)
        {
            // Pressed
            return false;
        }
        else if(mOldState.LeftButton == ButtonState.Pressed)
        {
            // Released.
            return true;
        }
    }                     
    return false;
}

The problem is this, whenever I now compile the game, I get an error in the 'Chest.cs' class: "Error 1 'RPGInAWeek.Button' does not contain a constructor that takes 0 arguments C:\Users\Chris\Desktop\Documents\C# Projects\2D Work\RPGInAWeek\RPGInAWeek\RPGInAWeek\Chest.cs 42 16 RPGInAWeek
"

public Chest()
{
    chests = new List<Rectangle>();
    closeRec = new List<Rectangle>();
    chestNames = new List<string>();
    dialogButtons = new List<Button>();
}

'Chest()' is underlined red whenever I compile... this is a recent error and only started when I created the 'OnClick' method inside the button.cs class. Any help would be greatly appreciated!

The 'Chest.cs' constructor looks like:

2
Contributors
2
Replies
33
Views
3 Years
Discussion Span
Last Post by CJMW
0

The error says your Button class is missing a default constructor yet an object of that class is being created as such.

Can you post the lines in particular from Chest.cs that are mentioned in the error?

0

Hey man dont worry about it, I found the problem. Its because my 'Chest.cs' class was inheriting the 'Button.cs' class:

class Chest : Button
{
    // Blah Blah Blah
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.