在我的代码中,我将 4 个具有不同值的键输入到 SortedList 中,每个键使用:
animations.Add(0, new Animation("prefix", textures, timer, looped));
排序列表是这样创建的:
private SortedList<int, Animation> animations = new SortedList<int, Animation>();
但是,当我调用更改正在播放的当前动画时,它会更改正在读取的键(ID),但不会更改值。该值始终保持在最后一个输入到 SortedList 中。
这是更改动画方法:
private void setAnimation(int ID)
{
Utilities.Log("Animation set to: " + ID + " of " + animations.Count);
curAnim = animations[ID];
curAnimID = ID;
curAnim.reset();
}
哪个输出
[29/07/2013 08:09:00 PM] Animation set to: 1 of 4
[29/07/2013 08:09:01 PM] Animation set to: 4 of 4
但视觉动画始终保持不变。更改由键盘事件触发。
我整天都被困在这上面,如果您能提供帮助,将不胜感激。代码的任何其他部分将根据要求提供。
编辑: curAnim 由 Animation 类中名为 getTexture() 的方法显示,该方法始终返回,就好像它是最后输入的条目一样。
插入:
//----------------IDLE----------------//
TextureBank idleTb = new TextureBank();
idleTb.add("idle1", c.Load<Texture2D>("idle"));
idleTb.add("idle1" + flip_str, Utilities.FlipHorizontal(c.Load<Texture2D>("characters/wife/idle")));
animations.Add(ANIMATIONS.IDLE, new Animation("idle", idleTb, 200, true));
//----------------JUMP----------------//
TextureBank jumpTb = new TextureBank();
jumpTb.add("jump1", c.Load<Texture2D>("jump"));
jumpTb.add("jump1" + flip_str, Utilities.FlipHorizontal(c.Load<Texture2D>("characters/wife/jump")));
animations.Add(ANIMATIONS.JUMP, new Animation("jump", jumpTb, 200, false));
//----------------PUNCH----------------//
TextureBank punchTb = new TextureBank();
punchTb.add("punch1", c.Load<Texture2D>("punch"));
punchTb.add("punch1" + flip_str, Utilities.FlipHorizontal(c.Load<Texture2D>("characters/wife/punch")));
animations.Add(ANIMATIONS.PUNCH, new Animation("punch", punchTb, 200, false));
//----------------WALK----------------//
TextureBank walkTb = new TextureBank();
walkTb.add("walk1", c.Load<Texture2D>("walk"));
walkTb.add("walk1" + flip_str, Utilities.FlipHorizontal(c.Load<Texture2D>("characters/wife/walk")));
walkTb.add("walk2", c.Load<Texture2D>("walk2"));
walkTb.add("walk2" + flip_str, Utilities.FlipHorizontal(c.Load<Texture2D>("characters/wife/walk2")));
animations.Add(ANIMATIONS.WALK, new Animation("walk", walkTb, 200, true));
setAnimation(ANIMATIONS.IDLE);