Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
PIXI Interaction - Retargeting canvas doesn't work as expected

I'm currently trying to make PIXI interaction work with DOM elements. My goal is as follow : when the user hovers a block, I want to show a dropdown (a red <div> for now), and when it leaves the div, I want the interaction to go back to the canvas.
To do so, I'm using the PIXI.InteractionManager and it's method setTargetElement. At first, the target is the canvas, and when the red box is shown, it becomes the target element. So far, everything works as expected. But when the cursor leaves the box, I'm using setTargetElement and give it the canvas, and then there is a strange issue, as shown in the gif.
enter image description here In the gif, you can see that the circle follows the cursor with no issue, then disappears on the red box (which is not a problem), and then, when the cursor leaves the box, the circle has a kind of scale effect (it's not a fixed offset because at 0,0, the cursor and the circle are superposed).

In a simplified version, this is what I do :

// Creates the circle that follows the pointer
initialization() {
  this.app.stage.on('pointermove', (e) => {
        circle.position.copyFrom(e.data.global)
  })
}

// When the blue box is hovered
onHoverBlock() {
  // Get the red box from the DOM
  const redBox = document.getElementById('red-box')
  // Tell the interaction manager to target the box
  this.app.renderer.plugins.interaction.setTargetElement(redBox)
}

// Called on the `mouseleave` of the red box
onMouseLeaveRedBox() {
  // Assign the canvas back to the interaction manager
  this.app.renderer.plugins.interaction.setTargetElement(
        this.canvasReference
  )

  // From this point, the circle doesn't follow the pointer anymore ๐Ÿ˜Ÿ
}

Do you know what is happening, and how to solve this issue ?

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Okay, the answer is pretty simple after all; setTargetElement also takes a resolution parameter that is set to 1 by default... while my app runs at a resolution of 2. ๐Ÿคฆโ€โ™‚๏ธ
I just need to pass my HTML element and my resolution (usually app.renderer.resolution) and it's working!

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!