几秒钟后删除列表中的对象XNA C#

几秒钟后删除列表中的对象XNA C#,c#,xna-4.0,C#,Xna 4.0,我计划制作一个射击游戏,玩家可以通过“+分数”来查看他们射击敌人得到了多少分。我已将它们中的每一个添加到列表中,如下所示: scoreList.Add(new ScoreHUD(Content.Load<SpriteFont>(@"arial"), 20, new Vector2(e.position.X, e.position.Y))); class ScoreList Position (vector) Value (string) Duration (intege

我计划制作一个射击游戏,玩家可以通过“+分数”来查看他们射击敌人得到了多少分。我已将它们中的每一个添加到
列表中,如下所示:

scoreList.Add(new ScoreHUD(Content.Load<SpriteFont>(@"arial"), 20, new Vector2(e.position.X, e.position.Y)));
class ScoreList
  Position (vector)
  Value (string)
  Duration (integer) = 60 ' 1 second
  visible = false
end class

class Score
  inhertis list of scorelist

  sub add(position, value, duration)
    ' add position, set visible to true
  end sub
  sub update()
    for each score in me
      if score visible
         score.duration -= 1
         if score.duration < 1 then score.visible = false;
      end if
    end for

    score.removeAll(function(c) c.visible = false) ' to remove unused
  end sub

  sub draw()
    for each score in me
      if score.visible then draw it
    end if
  end sub

end class
scoreList.Add(新的ScoreHUD(Content.Load(@“arial”)、20、新矢量2(e.position.X、e.position.Y));
20是杀了什么东西的分数。这显示在每个被毫无问题地杀死的敌人的位置上有“+20”


现在,我试着在3秒钟后将它们从游戏中移除。我曾尝试在
Update
函数中连接计时器函数,但不知道(我认为这是一个糟糕的做法)如何将每个计时器函数连接到每个分数中。有什么办法解决这个问题吗?

好的。。。我会用伪代码解释,我会这样说:

scoreList.Add(new ScoreHUD(Content.Load<SpriteFont>(@"arial"), 20, new Vector2(e.position.X, e.position.Y)));
class ScoreList
  Position (vector)
  Value (string)
  Duration (integer) = 60 ' 1 second
  visible = false
end class

class Score
  inhertis list of scorelist

  sub add(position, value, duration)
    ' add position, set visible to true
  end sub
  sub update()
    for each score in me
      if score visible
         score.duration -= 1
         if score.duration < 1 then score.visible = false;
      end if
    end for

    score.removeAll(function(c) c.visible = false) ' to remove unused
  end sub

  sub draw()
    for each score in me
      if score.visible then draw it
    end if
  end sub

end class
班级成绩表
位置(向量)
值(字符串)
持续时间(整数)=60'1秒
可见=假
末级
班级成绩
inhertis记分表列表
子添加(位置、值、持续时间)
'添加位置,将“可见”设置为true
端接头
子更新()
我的每一分
如果分数可见
得分。持续时间-=1
如果score.duration<1,则score.visible=false;
如果结束
结束
score.removeAll(函数(c)c.visible=false)删除未使用的
端接头
副绘图()
我的每一分
如果score.visible,则绘制它
如果结束
端接头
末级

下面是一个非常简单的示例,每2秒调用一次项目的删除

//Declares a timespan of 2 seconds
TimeSpan timeSpan = TimeSpan.FromMilliseconds(2000);


public override void Update(GameTime gameTime)
{
    // Decrements the timespan
    timeSpan -= gameTime.ElapsedGameTime;

    // If the timespan is equal or smaller time "0"
    if (timeSpan <= TimeSpan.Zero )
    {
        // Remove the object from list
        scoreList.RemoveAt(1);
        // Re initializes the timespan for the next time
        timeSpan = TimeSpan.FromMilliseconds(2000);

    }

    base.Update(gameTime)
}
//声明2秒的时间跨度
TimeSpan TimeSpan=TimeSpan.From毫秒(2000);
公共覆盖无效更新(游戏时间游戏时间)
{
//递减时间跨度
timeSpan-=gameTime.ElapsedGameTime;
//如果时间跨度等于或小于时间“0”

if(timeSpan)我只需要更改代码,以便它检查列表是否包含任何内容,并将removeat(1)更改为removeat(0)它就像魅力一样工作!谢谢!谢谢你,帮助别人总是一件很愉快的事^^。我确实使用了这个逻辑,在每个分数等级上加上了生命周期,在分数等级的更新中,我减少了它,使它不可见,但它不起作用,不管怎样,谢谢你,通过代码我控制了一切(敌人、星场、子弹、电源…),它起作用了。