简体   繁体   中英

Get UI ELement on touch

I'm sure I've read that there is a way of getting co-ordinates on Touch with Xna. But it's not really UIE, it's texture Draw in shapes.
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. I have defferents DragableObject , and my problem is when I move one Element, all others move too. 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);
            }
        }
    } 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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