Jump to content

Masking blocks interactivity

Recommended Posts

I'm extending the Container class as such:

class Layer extends PIXI.Container {
  // name: string;
  public overflowMask: PIXI.Graphics | null;

  constructor(options: LayerOptions) {

    this.zIndex = options.zIndex;
    this.name = options.id;
    this.sortableChildren = options.sortable;
    this.interactive = options.interactive;
    this.interactiveChildren = options.interactiveChildren || false;

    if (options.isMasked) {
      this.overflowMask = new PIXI.Graphics();
        .beginFill(0x00000, 1)
        .drawRect(0, 0, 500, 500)

      this.mask = this.overflowMask;
    } else {
      this.overflowMask = null;

  containsPoint(point: PIXI.Point): boolean {
    for (const child of this.children) {
      if (typeof (child as any).containsPoint === "function") {
        if ((child as any).containsPoint(point)) return true;
    return false;

As mentioned here, I'm overriding the containsPoint method but my Container's children loses their interactivity when they fall out of the masked area, what am I missing here?


Link to post
Share on other sites
41 minutes ago, themoonrat said:

hitArea trumps mask which trumps bounds

So since you have a mask, that'll be what's checked for interactivity, not the container itself. Give it a hitArea and that'll be used instead of the mask for interactivity.

I'm a little confused: do I need to give the Container a hitArea? Or its mask? I've been experimenting various approaches with no success. Thanks for your insight.

Link to post
Share on other sites

Sweet indeed! Giving the Container a hitArea works :)

Subsidiary question: my Container has a dynamic position (pixi-viewport) and I want to make sure its hitArea is always wrapping the whole stage, is there a way to do that? I guess I could just give it a massive hitArea, any other way? I tried override the containsPoint method, with no success:

containsPoint(point: PIXI.Point): boolean {
    return true;

This removes all interactivity on the Container for some reason.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...