dakrul Posted November 2, 2017 Share Posted November 2, 2017 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! ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 2, 2017 Share Posted November 2, 2017 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. Quote Link to comment Share on other sites More sharing options...
dakrul Posted November 2, 2017 Author Share Posted November 2, 2017 Oh sorry, I missed that. I thought I did something wrong. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted November 2, 2017 Share Posted November 2, 2017 6 minutes ago, dakrul said: Oh sorry, I missed that. I thought I did something wrong. Thanks for your help. Well, you've made the contribution Next time you can just post an issue or PR. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.