0
votes

I have project, inside there is background.cs class and game1.cs class, thats my background.cs class code:

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;
        }

    }
  }
}

and thats game1.cs class code (starting where I get error):

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;

' So, Scrolling scrolling1; is underlined, (as second one), it says that class Scrolling could not be found, but it exists! I am noob in XNA and I cant find why it isn't working. any help will be ok!

1

1 Answers

0
votes

Why do you have your Scrolling class nested into Backgrounds class in background.cs? The default visibility for nested classes in C# is private and therefore it is not visible to the Game1 class.

You should put this

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

}

into a file scrolling.cs. This gives Scrolling and Background the default visibility for classes (internal) which should work for your example.

You should to specify the visibility of classes explicitly. Have a look at: https://msdn.microsoft.com/en-us/library/ms173121.aspx