2017-05-13 8 views
0

CodingMadeEasy의 RPG 튜토리얼에 따라 C# 및 XNA/Monogame을 이해했습니다. 나는 그가 한 모든 것을했지만 여전히 스프라이트는 화면에 그려지지 않을 것입니다.Sprite는 SplashScreen 클래스를 그리지 않습니다.

GAME1 :

public class Game1 : Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 

    public Game1() 
    { 
     graphics = new GraphicsDeviceManager(this); 
     Content.RootDirectory = "Content"; 
    } 


    protected override void Initialize() 
    { 
     graphics.PreferredBackBufferWidth = (int)ScreenManager.Instance.Dimensions.X; 
     graphics.PreferredBackBufferHeight = (int)ScreenManager.Instance.Dimensions.Y; 

     base.Initialize(); 
    } 

    protected override void LoadContent() 
    { 
     spriteBatch = new SpriteBatch(GraphicsDevice); 

     ScreenManager.Instance.LoadContent(Content); 
    } 

    protected override void UnloadContent() 
    { 
     ScreenManager.Instance.UnloadContent(); 

     base.UnloadContent(); 
    } 

    protected override void Update(GameTime gameTime) 
    { 
     ScreenManager.Instance.Update(gameTime); 

     if (Keyboard.GetState().IsKeyDown(Keys.Escape)) 
     { 
      Exit(); 
     } 

     base.Update(gameTime); 
    } 

    protected override void Draw(GameTime gameTime) 
    { 
     spriteBatch.Begin(); 
     ScreenManager.Instance.Draw(spriteBatch); 
     spriteBatch.End(); 

     graphics.GraphicsDevice.Clear(Color.CornflowerBlue); 

     base.Draw(gameTime); 
    } 
} 

을 ScreenManager :

public class ScreenManager 
{ 
    private static ScreenManager instance; 
    public Vector2 Dimensions { private set; get; } 
    public ContentManager Content { private set; get; } 

    GameScreen currentScreen; 

    public static ScreenManager Instance 
    { 
     get 
     { 
      if (instance == null) 
       instance = new ScreenManager(); 

      return instance; 
     } 
    } 

    public ScreenManager() 
    { 
     Dimensions = new Vector2(640, 480); 
     currentScreen = new SplashScreen(); 

    } 

    public void LoadContent(ContentManager Content) 
    { 
     this.Content = new ContentManager(Content.ServiceProvider, "Content"); 
     currentScreen.LoadContent(); 
    } 

    public void UnloadContent() 
    { 
     currentScreen.UnloadContent(); 
    } 

    public void Update(GameTime gameTime) 
    { 
     currentScreen.Update(gameTime); 
    } 

    public void Draw(SpriteBatch spriteBatch) 
    { 
     currentScreen.Draw(spriteBatch); 
    } 
} 

GameScreen :

public class GameScreen 
{ 
    protected ContentManager content; 

    public virtual void LoadContent() 
    { 
     content = new ContentManager(
      ScreenManager.Instance.Content.ServiceProvider, "Content"); 
    } 

    public virtual void UnloadContent() 
    { 
     content.Unload(); 
    } 

    public virtual void Update(GameTime gameTime) 
    { 

    } 

    public virtual void Draw(SpriteBatch spriteBatch) 
    { 

    } 
} 

되는 SplashScreen :

여기

내 코드입니다
public class SplashScreen : GameScreen 
{ 
    Texture2D image; 
    string path; 

    public override void LoadContent() 
    { 
     base.LoadContent(); 
     path = "SplashScreen/Image"; 
     image = content.Load<Texture2D>(path); 
    } 

    public override void UnloadContent() 
    { 
     base.UnloadContent(); 
    } 

    public override void Update(GameTime gameTime) 
    { 
     base.Update(gameTime); 
    } 

    public override void Draw(SpriteBatch spriteBatch) 
    { 

     spriteBatch.Draw(image, Vector2.Zero, Color.White); 

     base.Draw(spriteBatch); 
    } 
} 

답변

1

스프라이트를 그리기 전에 화면을 지워야합니다. 위에서 제공 한 코드에서 스프라이트를 그려서 화면을 즉시 지 웁니다.

이 그것을 수정해야합니다 :

protected override void Draw(GameTime gameTime) 
{ 
    // move this here 
    graphics.GraphicsDevice.Clear(Color.CornflowerBlue); 

    spriteBatch.Begin(); 
    ScreenManager.Instance.Draw(spriteBatch); 
    spriteBatch.End(); 

    base.Draw(gameTime); 
}