Question

I'm working on a Windows app using XNA.

Actually I succeed moving my sprite, but I want to add a different action when the user touch the sprite but don't move it. I know TouchlocationState Enum exist but I don't understand the difference between Moved and Pressed.
For now I use Released and that's enough, I update the sprite position while it's not released and then I check collision. So how can I add only one touch method when it's clicked? I mean when the user tap the sprite but don't move it. Some code:

TouchPanelCapabilities touchCap = TouchPanel.GetCapabilities();
if (touchCap.IsConnected)
{
    TouchCollection touches = TouchPanel.GetState();
    if (touches.Count >= 1)
        {
        Vector2 PositionTouch = touches[0].Position;

        if (touches[0].State == TouchLocationState.Released)
        {
            // Pause button click and others buttons
            Mouseclik((int)PositionTouch.X, (int)PositionTouch.Y);       
        }

        if (!PausePopUp)
        {
            CheckMoove(PositionTouch);
            if (touches[touches.Count - 1].State == TouchLocationState.Released)
            {
            // this is where i try to add/check if its only "click" on my sprite
                    if (touches[0].Position == touches[touches.Count - 1].Postion)
                    {
                        TempoRectangle = ListSprite[save].ShapeViser;
                        isclicked = true;
                    }

My goal is to add a picturebox above the sprite to display information then if an other sprite is touched while the picturebox is diplayed, I want to draw a line between these 2 sprites.

Était-ce utile?

La solution

The difference is simple:

  • TouchLocationState.Pressed means that a new location is detected.
  • TouchLocationState.Moved means that the location position was updated or pressed at the same position

This means that you will get only a Pressed state for each touch action, a sequence of Moved every cycle while the touch is pressed, and when you release it you'll get a Released.

This is explained in the link you provided, too.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top