tags:

views:

154

answers:

1

Hi, I've got an issue with protected SceneItem scene = null; but I can't see why, the error is:

Inconsistent accessibility: field type 'AsteroidsFinal.Helpers.SceneItem' is less accessible than field 'AsteroidsFinal.Helpers.Screen.scene'`

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

namespace AsteroidsFinal.Helpers
{

abstract public class Screen
{
    #region Variables

    protected SceneItem scene = null;

    protected Screen overlay;

    protected SpriteBatch batch = null;

    protected Game game = null;

    #endregion

    #region Properties

    public Game GameInstance
    {
        get { return game; }
    }

    public SpriteBatch Sprites
    {
        get { return batch; }
    }    

    #endregion

    public Screen(AsteroidGame game)
    {
        this.game = game;

        if (game != null)
        {
            IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService));
            this.batch = new SpriteBatch(graphicsService.GraphicsDevice);
        }
    }

    public virtual GameState Update(TimeSpan time, TimeSpan elapsedTime)
    {
        scene.Update(time, elapsedTime);

        return (overlay == null) ? GameState.None : overlay.Update(time, elapsedTime);
    }

    public virtual void Render()
    {
        scene.Render();

        if (overlay != null)
            overlay.Render();
    }

    public virtual void Shutdown()
    {
        if (overlay != null)
            overlay.Shutdown();

        if (batch != null)
        {
            batch.Dispose();
            batch = null;
        }
    }

    public virtual void OnCreateDevice()
    {
        IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)game.Services.GetService(typeof(IGraphicsDeviceService));
        batch = new SpriteBatch(graphicsService.GraphicsDevice);
    }
}

}
+6  A: 

Screen is a public class. Because it's a public class, you can create derived types from it internally, within the assembly Screen resides in, or externally, outside the assembly Screen resides in.

"scene" is protected, meaning, it can be accessed from any class that derives from the class it resides in, which in this case, is Screen, however, you haven't declared SceneItem, which is the type of "scene" to be public. If a developer derives from Screen, but does it from outside the assembly, then he won't be able to access the type for SceneItem, because SceneItem is most likely internal.

To solve this, you either need to limit the accessibility modifier on Screen to be internal, or you'll need to modify the accessibility modifier on SceneItem to be public.

David Morton