スプライトシートデータにxmlファイルを使用しようとしています。長方形または別のフレームのリストを保持するフレームクラスがあります(フレーム自体、またはより多くのフレームのホルダーにすることができます)。xmlは、フレームのすべての長方形を保持します。コンテンツプロジェクトにxmlを追加し、Content.load( "xmlname")を使用してロードしました。
一度使用すると、これはすべて完全に正常に機能します。しかし、同じスプライトシート(したがって同じxmlデータファイル)を共有する2つのオブジェクトを作成すると、これら2つのオブジェクトが同じフレーム上にあると消えます。多くの不満を感じた後、xmlファイルは常に同じオブジェクトを返すため、フレームを共有するため、一度に1か所しかフレームを描画できないことがわかりました。
xmlファイルの短い部分は次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<rect>0 0 0 0</rect>
<frames>
<Item>
<rect>0 0 0 0</rect>
<frames>
<Item>
<rect>19 27 15 22</rect>
<frames></frames>
<label>DOWN</label>
</Item>
<Item>
<rect>2 27 15 23</rect>
<frames></frames>
<label>DOWN</label>
</Item>
<Item>
<rect>19 27 15 22</rect>
<frames></frames>
<label>DOWN</label>
</Item>
<Item>
<rect>36 27 15 23</rect>
<frames></frames>
<label>DOWN</label>
</Item>
</frames>
<label>DOWN</label>
</Item>
クラスの簡略版:
public class Frame
{
public Rectangle rect; //means this is an image
private Renderable renderable = null;
private List<Frame> frames;
private Texture2D texture;
private int currentFrame = 0;
使用例:
Sprite sprite1 = new Sprite();
sprite1.frame = Content.load<Frame>("xml");
sprite1.frame.getFrame(0).alpha = 0.5f;
Sprite sprite1 = new Sprite();
sprite2.frame = Content.load<Frame>("xml"); //<--- doesn't return a new object, returns the same object as sprite 1 uses
//frame 0 in sprite 2 has an alpha of 0.5 aswell, without having modified it
手動でxmlを逆シリアル化しようとしましたが、リストの逆シリアル化は悪夢です。私はここで何か間違ったことをしていますか?同じオブジェクトを返すほど奇妙に思えます