1
私は友人とゲームをプログラムしようとしていますが、スプライトの描画方法は非常に混乱しています。下のGame1クラスでコードを描くことができます。私の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);
}
}
}
、私は正常にそのスプライトと画面上のがテキストを描画することができます。しかし、私は別のクラスでスプライトを描きたいですが、私はそこに置くべきなんて全く考えていません。他のクラスで
、私はちょうどsprite.Draw
ような単純な何かを(//ここでは、xとスプライトがどこに行くのY COORDS、テクスチャの名前になります)、そして持っていることがしたいですそれはそうですが、それだけではうまくいかないようです。誰も私がこれをやり遂げる方法を知っていますか?
は、私はそれらのほとんどを削除したが、私はGame1.Draw(spritename)のようなものをやってみました、または私は自分のドローコードを記述しようとしたところより長いの試みでしたが、私は含まれていませんでした更新、それもどちらもうまくいきませんでした。あなたの時間と助けてくれてありがとう。 – Josh
私は今何をすべきかについて、まだ信じられないほど混乱しています。私はSpriteDrawというクラスを作り、その中に私は公共SpriteDraw( ベクトル2の位置、 にTexture2Dテクスチャ) { } 公共ボイド更新(GameTime gameTime) { } 公共ボイドドロー(SpriteBatch spriteBatch) { } Game1でSpiteDraw.Draw(spriteBatch)をどこに配置する必要があるかわかりません。 SpriteDraw.Update(gameTime)は毎回エラーが発生しています。私はLoadContentを – Josh
と入力してみました。spriteDraw = new SpriteDraw( 新しいVector2(0,30)、 新しいTexture2D "@/Sprites/dino/dinobackOvwld.png" )); しかし、それはどちらもうまくいかないようです – Josh