XNA 游戏 class 错误

XNA Game class Error

我有项目,里面有background.csclass和game1.csclass, 那是我的 background.cs class 代码:

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 class 代码(从我出错的地方开始):

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Rocket
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;

    Scrolling scrolling1;
    Scrolling scrolling2;

' 所以,滚动 scrolling1;有下划线,(作为第二个),它说 class 滚动找不到,但它存在!我是 XNA 的菜鸟,我找不到它为什么不工作的原因。任何帮助都可以!

为什么在 background.cs 中将滚动 class 嵌套到背景 class 中? C# 中嵌套 classes 的默认可见性是私有的,因此它对 Game1 class.

不可见

你应该把这个

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

}

到文件 scrolling.cs。这为滚动和背景提供了 classes(内部)的默认可见性,这应该适用于您的示例。

您应该明确指定 classes 的可见性。看看:https://msdn.microsoft.com/en-us/library/ms173121.aspx