最近、MonoMac で XNA を使い始めました。授業に問題があります。テクスチャと位置情報を内部に持つクラスを作成したい。また、描画機能を作りたいです。
私の考えは、spriteBatch と Content を周りに渡して、テクスチャを読み込んで後で描画できるようにすることでした。ただし、このオブジェクトに渡す Content オブジェクトはテクスチャをロードしません。クラス外で Content を試したところ、テクスチャが正常にロードされたので、テクスチャがそこにある必要があります。
public class TPlayer {
public Texture2D[] textures;
public ContentManager Content;
public SpriteBatch spriteBatch;
public int currentFrame;
public Rectangle position;
public TPlayer(ContentManager ccontent, SpriteBatch cspritebatch){
this.Content = ccontent;
this.spriteBatch = cspritebatch;
this.Content.RootDirectory = "Content";
this.currentFrame = 0;
this.position = new Rectangle(250,20,100,150);
this.LoadContent();
}
protected void LoadContent(){
this.textures[0] = this.Content.Load<Texture2D>("Textures/ToughStanding");
this.textures[1] = this.Content.Load<Texture2D>("Textures/ToughWalking1");
this.textures[2] = this.Content.Load<Texture2D>("Textures/ToughWalking2");
}
public void Draw(){
spriteBatch.Begin (SpriteSortMode.Deferred, BlendState.AlphaBlend);
this.spriteBatch.Draw (textures[0], this.position, Color.White);
this.spriteBatch.End ();
}
これは私がインスタンスを作成する方法です:
Player = new TPlayer(this.Content,this.spriteBatch);
多分私は間違ったモデルを使用しようとしています..クラス内でスプライトバッチとコンテンツを使用したくないかもしれませんが、スプライトバッチとコンテンツをグローバルにすることはできますか?
ご協力ありがとうございました