Class XNA游戏类错误

Class XNA游戏类错误,class,xna,Class,Xna,我有一个项目,里面有background.cs类和game1.cs类, 这是我的背景。cs类代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; namespace Rocket { class Backgrounds

我有一个项目,里面有background.cs类和game1.cs类, 这是我的背景。cs类代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

 namespace Rocket
 {
    class Backgrounds
  {
    public Texture2D texture;
    public Rectangle rectangle;
    public void Draw(SpriteBatch spriteBatch){
        spriteBatch.Draw(texture, rectangle, Color.White);
    }
    class Scrolling : Backgrounds{
        public Scrolling(Texture2D newTexture, Rectangle newRectangle){
            texture = newTexture;
            rectangle = newRectangle;
        }
        public void Update(){
            rectangle.X -= 3;
        }

    }
  }
}
这就是game1.cs类代码(从我得到错误的地方开始):

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用Microsoft.Xna.Framework;
使用Microsoft.Xna.Framework.Audio;
使用Microsoft.Xna.Framework.Content;
使用Microsoft.Xna.Framework.GamerServices;
使用Microsoft.Xna.Framework.Graphics;
使用Microsoft.Xna.Framework.Input;
使用Microsoft.Xna.Framework.Media;
命名空间火箭
{
/// 
///这是游戏的主要类型
/// 
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
滚动滚动1;
滚动滚动2;
"
因此,滚动滚动1;带有下划线(作为第二个),它说找不到类滚动,但它存在!我在XNA中是noob,我找不到为什么它不工作。任何帮助都可以!

为什么要将滚动类嵌套在background.cs中的Backgrounds类中?C#中嵌套类的默认可见性是私有的,因此它对Game1类不可见

你应该把这个

class Scrolling : Backgrounds{
    public Scrolling(Texture2D newTexture, Rectangle newRectangle){
        texture = newTexture;
        rectangle = newRectangle;
    }
    public void Update(){
        rectangle.X -= 3;
    }

}
这为scrolling和Background提供了类(内部)的默认可见性,这些类应该适用于您的示例


您应该明确指定类的可见性。请查看:

Yes,因为您有一个具有两个参数的构造函数:public Scrolling(Texture2D newexture,Rectangle newRectangle)
class Scrolling : Backgrounds{
    public Scrolling(Texture2D newTexture, Rectangle newRectangle){
        texture = newTexture;
        rectangle = newRectangle;
    }
    public void Update(){
        rectangle.X -= 3;
    }

}