Skip to main content

Enabling Interactivity

We've created nodes and added them to scenes. But we haven't allowed any user responses. In this section, we'll learn how to make our nodes interactive.

By default, nodes are not interactive. To make a node interactive, we need to do two things:

  1. Set the node's isUserInteractionEnabled property to true.
  2. Decide what kind of interaction or "event" to allow and how to respond to it.

Below, we create a button and set its isUserInteractionEnabled property to true. To define what code is executed when the user taps down on the button, we call the onTapDown() method on the button and pass in the code to execute: a message to the console that says "You pushed it!".

info

The window under the code area displays output from the browser console log. You'll see m2c2kit diagnostics, as well as messages we print there. This is the same output you would see if you opened your browser's developer tools.

Loading...
Explore:
  • Count how many times you pushed the button.
  • What if you set isUserInteractionEnabled: false? The node will not respond.
  • The node will not respond if you omit isUserInteractionEnabled: true.