2009-02-08 8 views
1

내가 protected SceneItem scene = null;에 문제가있어하지만 난 왜 볼 수없는 오류는 다음과 같습니다불일치 오류 C#을

일관성 접근성 : 필드 유형 'AsteroidsFinal.Helpers.SceneItem이'필드보다 접근 ' 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

화면 공개 클래스입니다. 그것은 공용 클래스이기 때문에 조립 화면에있는 외부, 당신은 외부에서 조립 화면에있는 내에서 내부적으로 그것에서 파생 된 형식을 만들거나 할 수 있습니다.

"장면"보호, 의미, 그것은 어떤에서 액세스 할 수 있습니다 이 클래스는 상주하는 클래스에서 파생 된 클래스이며이 경우 Screen입니다. 그러나 "장면"의 유형 인 SceneItem을 선언하지 않았습니다. 개발자가 Screen에서 파생되었지만 어셈블리 외부에서 수행하는 경우 SceneItem은 내부에있을 가능성이 높기 때문에 SceneItem의 형식에 액세스 할 수 없습니다.

이 문제를 해결하려면 Screen의 액세스 가능성 수정자를 internal로 제한해야하거나 SceneItem의 접근성 수정자를 public으로 수정해야합니다.