Skip to main content

Hit area

The "hit area" or "hit box" is the area of a node that responds to user input. The hit area is the same as the node's size.

Changing the hit area

You may want an area larger that the node's size to respond to user input. For example, you may need a button to respond to user input even if the user taps slightly outside the button's bounds.

To do this, create an "invisible" node that is larger than the node you want to respond to user input. For example, if the button is width 80 and height 50, create an invisible rectangle that is width 110 and height 80. Then, add the button as a child of the rectangle. Finally, handle user events on the rectangle, not the button.

Below, if you tap a little bit outside the button, the program still recognizes user input -- you're tapping the hit area of the invisible rectangle, not the button.

Loading...