本文介绍了移动多个物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用使用C#的XNA2D.我是C#的新手
我正在尝试移动一组对象.到目前为止,我一次只能移动一个对象.
这是我的代码.
I am using XNA2D which uses C#. I am new to C#
i am trying to move a group of objects around. So far, i am able to move only one object at a time.
Here is my code.
if (input == null)
{
throw new ArgumentNullException("input"");
}
mouseStateCurrent = Mouse.GetState();
drag = Vector2.Zero;
foreach (ALU a in ALU.List)
{
if (a.Rectangle.Contains(mouseStatePrevious.X, mouseStatePrevious.Y) &&
!dragging &&
mouseStateCurrent.LeftButton == ButtonState.Pressed)
{
selectedALU = a;
dragging = true;
drag.X = selectedALU.Position.X - mouseStatePrevious.X;
drag.Y = selectedALU.Position.Y - mouseStatePrevious.Y;
}
if (mouseStateCurrent.LeftButton == ButtonState.Released)
{
if (dragging)
{
selectedALU.Position.X = (float)((Math.Round(selectedALU.Position.X / 64)) * 64);
selectedALU.Position.Y = (float)((Math.Round(selectedALU.Position.Y / 64)) * 64);
}
dragging = false;
}
mouseStatePrevious = mouseStateCurrent;
}
推荐答案
这篇关于移动多个物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!