我希望DrawableGameComponent
类中的方法在满足特定条件之前不返回
假设我有这个课程(来自DrawableGameComponent
课程的片段):
public override void Update(GameTime gameTime)
{
if (moving && pixFromLastMove <= distanceToMove)
{
position += velocity;
pixFromLastMove += velocity.Length();
}
else
{
moving = false;
}
if (rotating)
{
rotation += 0.1f;
var cRotation = MathHelper.Clamp(rotation, -MathHelper.PiOver2, angleBeforeRotation + degToRotate);
if (cRotation != rotation)
{
rotation = cRotation;
angleBeforeRotation = rotation;
rotating = false;
}
}
base.Update(gameTime);
}
public void Ahead(int pix)
{
moving = true;
distanceToMove = pix;
pixFromLastMove = 0;
velocity = new Vector2((float) Math.Cos(rotation), (float) Math.Sin(rotation))*5.0f;
//DO NOT RETURN UNTIL THIS ROBOT HAS MOVED TO ITS DESTINATION
}
public void TurnLeft(int deg)
{
rotating = true;
degToRotate = MathHelper.ToRadians(deg);
angleBeforeRotation = rotation;
//DO NOT RETURN UNTIL THIS ROBOT HAS BEEN FULLY ROTATED
}
这个类正在Draw()
主线程中绘制()(因为这个drawablegamecomponent在单独的线程中执行),并且在主线程中我有一个我想要按顺序执行的命令列表......但是目前,因为Ahead
方法在为 赋值后立即返回velocity
,这些方法将几乎同时运行,而这反过来只是同时执行所有动画。
那么你认为我应该怎么做才能防止命令(等)的方法Ahead
在TurnLeft
满足特定条件之前返回?