简体   繁体   English

接触UI ELement

[英]Get UI ELement on touch

I'm sure I've read that there is a way of getting co-ordinates on Touch with Xna. 我确信我已经读过,有一种方法可以在Xna与Touch上取得坐标。 But it's not really UIE, it's texture Draw in shapes. 但这不是真正的UIE,而是纹理绘制形状。
For the moment I make them move like that: 目前,我让他们像这样移动:

void update()
  TouchPanelCapabilities touchCap = TouchPanel.GetCapabilities();            
            if (touchCap.IsConnected)
            {
                TouchCollection touches = TouchPanel.GetState();
                if (touches.Count >= 1)
                {
                    Vector2 PositionTouch = touches[0].Position;
                    Position.X = PositionTouch.X - (t_Sprite.Width / 2);
                    Position.Y = PositionTouch.Y - (t_Sprite.Height / 2);
                }
           } 

it's the method of my DragableObject Class. 这是我的DragableObject类的方法。 I have defferents DragableObject , and my problem is when I move one Element, all others move too. 我有不同的DragableObject ,而我的问题是当我移动一个Element时,其他所有元素也都移动了。 Anyone helps? 有人帮忙吗?

What i have finally done and "works" for the moment. 我现在终于完成了哪些工作并“正常工作”。 But dunno if its the good way for implement collision later. 但是不知道它是否是以后实现碰撞的好方法。

public void Update(GameTime gametime)
{
    Currentposition = Station.Position;

    TouchPanelCapabilities touchCap = TouchPanel.GetCapabilities();
    if (touchCap.IsConnected)
    {
        TouchCollection touches = TouchPanel.GetState();
        if (touches.Count >= 1)
        {
            Vector2 PositionTouch = touches[0].Position;
            for (int i = 0; i < ListDragObj.Count(); i++)
            {
                if (ListDragObj[i].Shape.Contains((int)PositionTouch.X, (int)PositionTouch.Y))
                {
                    ListDragObj[i].selected = true;
                }
                else
                {
                    ListDragObj[i].selected = false;
                }
                ListDragObj[i].Update(PositionTouch);
            }
        }
    } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM