友人とゲームをプログラミングしようとしていますが、スプライトの描画方法について非常に混乱しています。以下の Game1 クラスでコードを描画できます。
namespace SweetGeorgiaBrown
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
enum GameStates { TitleScreen, Overworld, Menu, Battle, GameOver };
GameStates gameState = GameStates.Battle;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D dinoTex;
Texture2D alienTex;
Texture2D robotTex;
Texture2D eroboTex;
SpriteFont basic;
private Vector2 textLocation = new Vector2(20, 20);
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
public class Health
{
public static int dinoHP = 300;
public static int alienHP = 200;
public static int robotHP = 100;
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
dinoTex = Content.Load<Texture2D>(@"Sprites\dino\dinoFrontOvwld");
alienTex = Content.Load<Texture2D>(@"Sprites\alien\alienFrontOvwld");
robotTex = Content.Load<Texture2D>(@"Sprites\robot\robotFrontOvwld");
eroboTex = Content.Load<Texture2D>(@"Sprites\robo1\robo1OvwldFront");
basic = Content.Load<SpriteFont>(@"Fonts\Basic");
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
switch (gameState)
{
case GameStates.Battle:
break;
}
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
// TODO: Add your drawing code here
if ((gameState == GameStates.Battle))
{
spriteBatch.DrawString(
basic,
"ASDFASDFADFASDFA ", textLocation, Color.Black);
spriteBatch.Draw(
dinoTex, textLocation, Color.White);
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}
私の Game1 コードでは、そのスプライトとテキストを画面上に正常に描画できます。しかし、別のクラスにスプライトを描きたいのですが、そこに何を置けばいいのか全くわかりません。
他のクラスでは、次のような簡単なことをしたいと思います
sprite.Draw(//ここでは、スプライトが移動する場所の x 座標と y 座標、テクスチャの名前になります)、それで十分ですが、そのようには機能しないようです。どうすればこれを行うことができるか知っている人はいますか?