Menus
It's time we made some menus. If we want menus, we need buttons to press. But before we make the buttons, we need to perform the following steps:
Because a button uses touch to determine if it's being pressed, we need to add the current touch state to the render context so all objects have the latest touch state. We do this by adding an extra property to the render context and by setting the latest touch state in the
Update
method of the scene manager.// Extra property of the render context public TouchCollection TouchPanelState { get; set; } // Update the TouchPanelState in the // Update of the Scene Manager RenderContext.TouchPanelState = TouchPanel.GetState();
Add an extra HitTest method to our
GameObject2D
. This because touch returns a point instead of a rectangle. We can check if a point is in a rectangle by using theContains
method. Note that we use an extra argument that specifies whether we want to test all the children. This is not always the case, as you will see in the...