0
\$\begingroup\$

I'm trying to make a clickable menu for my XNA Windows Phone game. If the player makes a tap gesture on a button(rectangle), something will happen. For example, the game will start if you touch the START button. But I always have difficulties with collision detection. If the player touches a button, the collision is not always working. If the player touches the left border or the top of the button, nothing happens. But on the other hand, if the player touches the area next to the right side or next to the bottom of the button, the collision happens. I want that the collision just happens when the player touches the button, and not when the player touches the area next to it.

What is wrong? How can I solve the problem? Is there a better way to make a clickable menu?

while (TouchPanel.IsGestureAvailable) 
        { 
            GestureSample gs = TouchPanel.ReadGesture(); 
            switch (gs.GestureType) 
            { 
                case GestureType.Tap: 
                     { 
                    tapState = new Rectangle((int)gs.Position.X, (int)gs.Position.Y, 1, 1); 
                    nextmenu = true; 
                     } 
                break; 
            } 

                if (nextmenu == true) 
                { 
                 if (buttonBounds.Intersects(tapState)) 
                { 
                    jchangetomenu = true; 
                } 
                 nextmenu = false; 
                } 
        } 
\$\endgroup\$
0
\$\begingroup\$

See this related answer https://stackoverflow.com/questions/18168807/xna-hold-screen-to-move-object

Check collision with button here case TouchLocationState.Pressed:.Alson you can make rectangle to represent your button bound and check collision with it using http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle.contains.aspx Put your change menu state logic here case TouchLocationState.Released:.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.