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)
{
}
}
スプラッシュ:
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);
}
}