C# c“方法无过载”;方法“;接受0个参数,名称为;名称“;在当前上下文中不存在

C# c“方法无过载”;方法“;接受0个参数,名称为;名称“;在当前上下文中不存在,c#,debugging,visual-studio-2013,xna,xna-4.0,C#,Debugging,Visual Studio 2013,Xna,Xna 4.0,编辑 现在我原来的问题已经解决了,但现在我得到的只是“非静态字段、方法或属性需要对象引用”。在研究了这个错误之后,很明显,当你创建一个静态函数的实例时会发生什么,但是我想要调用的函数不是静态的 编辑结束* 我已经搜索了互联网,试图找到一个解决方案,试图找到一种方法来修复这些错误,这样我的游戏就可以运行了。我正在使用最新版本的Microsoft Visual Studio、c#和XNA 4.0。我的问题出现在Game1.cs的第146行,我试图引用ManageTheScreens.cs第28行的D

编辑

现在我原来的问题已经解决了,但现在我得到的只是“非静态字段、方法或属性需要对象引用”。在研究了这个错误之后,很明显,当你创建一个静态函数的实例时会发生什么,但是我想要调用的函数不是静态的

编辑结束*

我已经搜索了互联网,试图找到一个解决方案,试图找到一种方法来修复这些错误,这样我的游戏就可以运行了。我正在使用最新版本的Microsoft Visual Studio、c#和XNA 4.0。我的问题出现在Game1.cs的第146行,我试图引用ManageTheScreens.cs第28行的Draw方法(由于调试原因而更改),但我遇到了两个错误(在标题中说明)。如果有人能帮忙,我将不胜感激,如果这是一个非常简单的修复,我也道歉,我浪费了你的时间

///this is in Game1.cs

 protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();
       /*this is how i'm trying to reference the draw method in the other class*/
           ManageTheseScreens.Draw(ActiveScreen);

            spriteBatch.End();


            base.Draw(gameTime);
        }
///this is ManageTheseScreens.cs

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

using WindowsGame1.Screens;

namespace WindowsGame1
{
    public class ManageTheseScreens
    {
        ArrayList Screens;
        Screen CurrentScreen;

        public ManageTheseScreens()
        {
            Screens = new ArrayList();
            Screens.Add(new TitleScreen());

            CurrentScreen = (Screen)Screens[0];
        }
///this is what i'm trying to reference
        public void Draw(SpriteBatch ActiveScreen)
        {

            CurrentScreen.Draw(ActiveScreen);
        }
    }
}

在尝试调用“ManageThesScreens”上的方法之前,您永远不会创建“ManageThesScreens”的实例。这就是你的第一个问题的来源

在<代码>Spritebatch Spritebatch下在第33行添加以下行:
managethescreens managethescreens=newmanagethescreens()它的作用是创建一个可以使用的“ManageThesScreens”对象的新实例

然后,代替
managethessescreens.Draw(ActiveScreen)使用
管理这些屏幕。绘制(spriteBatch)我假设您想在这里传递一个spritebatch,它基于“ManageTheseScreens”类中的代码。这就是第二个错误的来源,因为“Game1”中没有名为“ActiveScreen”的变量

Game1类现在应该如下所示:

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    ManageTheseScreens manageTheseScreens = new ManageTheseScreens();

    int screenWidth;
    int screenHight;

    /// <summary>
    /// StartingLoad from ScreenSwitcher.cs
    /// </summary>
    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        this.IsMouseVisible = true;
        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        Content_Manager.getInstance().loadTextures(Content);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();

        manageTheseScreens.Draw(spriteBatch);

        spriteBatch.End();

        base.Draw(gameTime);
    }

}
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
ManageTheseScreens ManageTheseScreens=新的ManageTheseScreens();
int屏幕宽度;
int屏幕高度;
/// 
///从ScreenSwitcher.cs开始加载
/// 
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
/// 
///允许游戏在开始运行之前执行任何需要的初始化。
///在这里,它可以查询任何必需的服务,并加载任何非图形化的服务
///相关内容。调用base.Initialize将枚举所有组件
///并对它们进行初始化。
/// 
受保护的覆盖无效初始化()
{
//TODO:在此处添加初始化逻辑
this.IsMouseVisible=true;
base.Initialize();
}
/// 
///LoadContent将在每个游戏中调用一次,并且是加载的地方
///你所有的内容。
/// 
受保护的覆盖void LoadContent()
{
spriteBatch=新spriteBatch(图形设备);
Content\u Manager.getInstance().loadTextures(内容);
}
/// 
///这就是所谓的比赛应该平局的时候。
/// 
///提供计时值的快照。
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
spriteBatch.Begin();
管理这些屏幕。绘制(spriteBatch);
spriteBatch.End();
基础。抽签(游戏时间);
}
}
(我删除了一些注释和不相关的函数)


希望这会有所帮助。

请在出现此错误的行周围提供代码。首先,从粘贴问题中的代码开始。如果它发生在许多地方,只需包括一小部分来说明问题。不要链接到外部文件;我们不打算筛选您的代码和/或自己打开它来查看它有什么问题。抱歉,不知道什么更容易,因为错误发生在对其他类的引用中。现在我收到一个错误,它说“非静态字段、方法或属性需要对象引用”错误发生在哪里?听起来好像有一个变量没有创建still的实例。我已经用我猜代码应该是什么样子的更新了答案。这正是我所拥有的。我只是得到“非静态字段、方法或属性需要对象引用”。在研究了这个错误之后,很明显,当你创建一个静态函数的实例时会发生什么,但是我想要调用的函数不是静态的。