Jump to content

Why is PIXI.interaction.InteractionEvent undefined?


dakrul
 Share

Recommended Posts

Hey everyone,

this is my first post, so I hope I do this right.

Let me explain, what I wanted to do:
I created a GameObject class so that all my objects inherit from this class.
The GameObject is interactive and I was thinking about to give it some default methods, that can be used for:
 

this.on('pointerdown', <__put_default_function_here__>);

If an object that inherit from GameObject needs a different action as you click on it, you can simply switch the callback function to another default method or you could create a new method inside the new object.
So one of this default methods looks like this:
 

//ECMA6

shot_this(from=this.parent.player) {
    console.log('POP!');
    console.log(from);
    console.log('shot something:');
    console.log(this);
}

As you can see, I thought that if i do this: "this.on('pointerdown', this.shot_this)" the from-variable would be undefinded and than would be set to my player object.
But as it turns out, this is wrong.
The first parameter of the callback function of .on() is the InteractionEvent.

Now lets go to my Problem:

My Problem is definitely not that the first parameter of the callback-function is the InteractionEvent, my problem is, that I can't check for it.

The default method shot_this will be also used by an NPC AI to shot at things, so I must check if the first parameter is an InteractionEvent.
Something like this isn't working:
 

//ECMA6

shot_this(from) {
    if (from instanceof PIXI.interaction.InteractionEvent) {
        console.log('yeah it is an InteractionEvent');
    } else {
        ...
    }
}

PIXI.interaction.InteractionEvent is always undefined.

So my question is: How do i check if the first parameter is an InteractionEvent?

And why is PIXI.interaction.InteractionEvent undefined, even if i try to access this by Chrome Developer Tools?


I hope you understand my problem and can help me.
Have a great day everyone!

Link to comment
Share on other sites

Because we forgot to export it. https://github.com/pixijs/pixi.js/blob/dev/src/interaction/index.js

You can check if it has "target" or "currentTarget".

Currently we are not accepting PR's in v4, but I'll make sure this will be fixed in v5.

There are many things you can learn from pixi sources, its not a black box.

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...