我一直在使用 Simple 尝试将我的 XML 文件读入此类。我真的不知道我是否正确地注释了这些类。
我不知道我是否需要这部分:
public Frame()
{
super();
}
public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration )
{
this.Num = num;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.OffsetX = offsetx;
this.OffsetY = offsety;
this.Duration = duration;]
super() 是做什么的?我需要getter/setter吗?我添加的是getter还是setter?他们是自动称呼自己还是什么?
这是完整的课程:
public class SpriteAnimationManag
{
// Animation frame class
@Element(name = "Frame")
public class Frame
{
@Element(name = "Num")
public int Num;
@Element(name = "X")
public int X;
@Element(name = "Y")
public int Y;
@Element(name = "Width")
public int Width;
@Element(name = "Height")
public int Height;
@Element(name = "OffSetX")
public int OffsetX;
@Element(name = "OffSetY")
public int OffsetY;
@Element(name = "Duration")
public float Duration;
public Frame()
{
super();
}
public Frame(int num, int x, int y, int width, int height,int offsetx,int offsety, int duration )
{
this.Num = num;
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
this.OffsetX = offsetx;
this.OffsetY = offsety;
this.Duration = duration;
}
}
// Animaiton class to hold the name and frames
public class Animation
{
@Element(name = "Name")
public String Name;
@Element(name = "FrameRate")
public int FrameRate;//may need elementarray or list???
@Element(name = "Loop")
public boolean Loop;
@Element(name = "Pingpong")
public boolean Pingpong;
@ElementArray(name = "Frames")
public Frame[] Frames;
public Animation()
{
super();
}
public Animation(String name, int framerate, boolean loop, boolean pingpong, Frame[] frames)
{
this.Name = name;
this.FrameRate = framerate;
this.Loop = loop;
this.Pingpong = pingpong;
this.Frames = frames;
}
}
// The Sprite Texture stores the Sprite Sheet path.fr
public class SpriteTexture
{
// The Sprite Sheet texture file path
@Element(name = "path")
public String Path;
public SpriteTexture()
{
super();
}
public SpriteTexture(String path)
{
this.Path = path;
}
}
// Aniamtion Set contains the Sprite Texture and Animaitons.
@Root(name = "Animations")
public static class XNAAnimationSet
{
// The sprite texture object
@Element(name = "Texture")
public SpriteTexture SpriteTexture;
// The animation array in the Animation Set
@ElementArray(name = "Animation")
public Animation[] Animations;
public XNAAnimationSet()
{
super();
}
public XNAAnimationSet(SpriteTexture spritetexture, Animation[] animations)
{
this.SpriteTexture = spritetexture;
this.Animations = animations;
}
}
// Sprite Animation Manager class
public final static class SpriteAnimationManager
{
private static final String XNAAnimationSet = null;//was static private static
public static int AnimationCount;
// Read the Sprite Sheet Description information from the description xml file
public static XNAAnimationSet Read(String filename) throws Exception
{
XNAAnimationSet animationSet = new XNAAnimationSet();
Serializer serializer = new Persister();
try {
animationSet = serializer.read(XNAAnimationSet.class, filename );
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
// Count the animations to Animation Count
AnimationCount = animationSet.Animations.length;
return animationSet;
}
}
}
我一直试图通过尝试将类写入文件来查看正在读取的内容。该文件已创建,但它是空的。
有人能告诉我我是否正确注释了吗?我究竟做错了什么?