Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3980

Why is PIXI.interaction.InteractionEvent undefined?

$
0
0

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!


Viewing all articles
Browse latest Browse all 3980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>