handleEvent method

bool handleEvent (
  1. SpriteBoxEvent event
)

Handles an event, such as a pointer (touch or mouse) event.

Override this method to handle events. The node will only receive events if the userInteractionEnabled property is set to true and the isPointInside method returns true for the position of the pointer down event (default behavior provided by NodeWithSize). Unless handleMultiplePointers is set to true, the node will only receive events for the first pointer that is down.

Return true if the node has consumed the event, if an event is consumed it will not be passed on to nodes behind the current node.

// MyTouchySprite gets transparent when we touch it
class MyTouchySprite extends Sprite {

  MyTouchySprite(Image img) : super (img) {
    userInteractionEnabled = true;
  }

  bool handleEvent(SpriteBoxEvent event) {
    if (event.type == PointerDownEvent) {
      opacity = 0.5;
    }
    else if (event.type == PointerUpEvent) {
      opacity = 1.0;
    }
    return true;
  }
}

Implementation

bool handleEvent(SpriteBoxEvent event) {
  return false;
}