XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Help solving error: no suitable method found to override

Last post 07/11/2009 20:20 by Blindsyde. 4 replies.
  • 07/11/2009 1:22

    Help solving error: no suitable method found to override

     I just finished chap 4 from "Beginning XNA 3.0 Game Programming from Novice to Professional" but I am getting an error stating "'RockRain002.ActionScene.Hide()': no suitable method found to override". I need help (1) understanding what this error means and (2) help solving it please.
    Below is sections of the code showing everywhere "Hide" appears, with the part in red showing where the error is.


    public class GameScene : Microsoft.Xna.Framework.DrawableGameComponent
        {
            public virtual void Hide()
            {
                Visible = false;
                Enabled = false;
            }
        }


    public class StartScene : GameScene
        {
            public override void Hide()
            {
                MediaPlayer.Stop();
                base.Hide();
            }

        }


    public class ActionScene : Microsoft.Xna.Framework.DrawableGameComponent
        {
            public override void Hide()
            {
                //stop the background music
                MediaPlayer.Stop();

                //stop the rumble
                rumblePad.Stop(PlayerIndex.One);
                rumblePad.Stop(PlayerIndex.Two);

                base.Hide();
            }
        }


    public class Game1 : Microsoft.Xna.Framework.Game
        {
            protected void ShowScene(GameScene scene)
            {
                activeScene.Hide();
                activeScene = scene;
                scene.Show();
            }
        }


    Thank you for any help,
    Blindsyde
  • 07/11/2009 1:32 In reply to

    Re: Help solving error: no suitable method found to override

    The override keyword can only be used to override virtual methods - that is - methods defined using the virtual keyword - so you can think of the override keyword as a partner keyword to the virtual keyword (and the abstract keyword).

    Your GameScene class is ok, it has defined a virtual method called Hide.

    To override the Hide method in a subclass, the subclass must inherit from your GameScene class.

    The compiler error is telling you that the ActionScene class does not inherit from a class with a virtual Hide method - that is the clue to your error.

    I am guessing you want your ActionScene class to subclass GameScene, rather than DrawableGameComponent. If you fix this, you fix your problem.


    Game hobbyist hell-bent on coding a diabolical Matrix
  • 07/11/2009 2:03 In reply to

    Re: Help solving error: no suitable method found to override

    Thanks, changing the ActionScene to a GameScene fixed the problem I was having (and oddly enough then drew attention to a few spelling mistakes!).

    Thank you for explaining the override and virtual keywords. This was the first time I had come across virtual, so I'm going to have to find out more about it, and what all it can do.

    Blindsyde
  • 07/11/2009 2:06 In reply to

    Re: Help solving error: no suitable method found to override

    Blindsyde:
    so I'm going to have to find out more about it, and what all it can do.
    Look up Polymorphism
    Game hobbyist hell-bent on coding a diabolical Matrix
  • 07/11/2009 20:20 In reply to

    Re: Help solving error: no suitable method found to override

    Thanks, I will
Page 1 of 1 (5 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG