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:
- Set the node's
isUserInteractionEnabled
property totrue
. - 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!"
.
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.