Jump to content

trying to delegate events to div overlaying pixi canvas


andreas_d
 Share

Recommended Posts


Hi guys,


 


Unsure what the correct procedure is to delegate mouse events to a different DOM element.


 


Currently I am attempting by doing the following:





var dom = document.querySelector('.overlay');
renderer.plugins.interaction.setTargetElement(dom);


I am applying an eventlistener on a container (RenderStack extends the PIXI.Container)


 




var stage = new PIXI.Container();
var stack = new RenderStack();

stage.addChild(stack);

stack.interactive=true;
stack.on('mousedown', function(e){
//debugger;
console.log('mousedown');
//var offset = e.data.getLocalPosition(e.target);
addLayer();
})


 


Inspecting the code in the console i have noticed that:


 


InteractionManager.prototype.onMouseDown is called on mousedown when div.overlay is clicked on, but the 


InteractionData object stored in InteractionManager's .mouse property has x and y values set to NaN .  From what I can see InteractionData is stored in the .mouse property on instantiation of InteractionManager and haven't found where it is updated.


 


As a result 



hit = displayObject.containsPoint(point)

 in InteractionManager.prototype.processInteractive never returns true and the eventlistener is never triggered (console never logs 'mousedown')


 


Hope this all makes sense.  I'm less inclined to think this is a bug than an incorrect usage of setTargetElement by me( which is actually labelled as private in the framework...)


 


Any insight on how I can get this to work?  I need to overlay dom elements over the pixi canvas so really need a way to delegate interaction events.


 


Thanks for any feedback


 


Andreas


Link to comment
Share on other sites

I may be way off but this is where the issue might be occuring:

 

from InteractionData.js

    /**     * This point stores the global coords of where the touch/mouse event happened     *     * @member {Point}     */    this.global = new core.Point();

I'm confused as to what the difference between core.Point() and math.Point() are.. also haven't found any place in the code where the x and y properties of the Point are populated with position values ( for ex from .clientX / .clientY )

Link to comment
Share on other sites

I may be way off but this is where the issue might be occuring:

 

from InteractionData.js

    /**     * This point stores the global coords of where the touch/mouse event happened     *     * @member {Point}     */    this.global = new core.Point();

I'm confused as to what the difference between core.Point() and math.Point() are.. also haven't found any place in the code where the x and y properties of the Point are populated with position values ( for ex from .clientX / .clientY )

 

There is no difference. InteractionData is in a plugin so it requires the core lib and access the point object. `math.Point` is used within the core lib since it just requires the math lib.

Link to comment
Share on other sites

Aha !  thanks for that,

 

I was digging around looking for a different Point class somewhere.  Still trying to wrap my head around the node 'require' system :[ .  

 

Any idea when /where InteractionData.global  is populated with event.clientX/Y -type values ?

 

I can't figure that out.  For some reason when InteractionManager.interactionDOMElement is changed using InteractionManager.setTargetElement() and the Events are removed/readded , InteractionManager.mouse.global Point values become NaN,  causing all kinds of mischief.

Link to comment
Share on other sites

omg  I don't know how I missed that...  

That's so obvious.  Well it's domElement.width  property that was causing the problem .. 

solved it by adding the following to index.html

var dom = document.querySelector('.overlay');dom.width = dom.offsetWidth;dom.height = dom.offsetHeight; 

Thank you for your help!

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