Skip to main content
Participant
April 30, 2020
Question

Use hitTest in js

  • April 30, 2020
  • 1 reply
  • 481 views

Hi,
I would like to detect the collision of two clips (b1 and v1) when clicking on a button (btvo). In js so that it works in html5. I tried with this code, but it doesn’t work you would have a solution? 

 

this.btvo.addEventListener("click", playClicked.bind(this));
function playClicked() {

var pt = v1.localToLocal(100,0,b1);
if (b1.hitTest(pt.x, pt.y)) { this.score.text = "OK"}

if (this.b1.hitTest(this.v1))

else {this.score.text = "No"}
}

 

Thank you

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    May 4, 2020

    try:

     

    var pt = this.v1.localToLocal(100,0,this.b1);
    if (this.b1.hitTest(pt.x, pt.y)) {

    this.score.text = "OK";

    } else {
    this.score.text= "No";

    }

    J-YvesAuthor
    Participant
    May 5, 2020

    Thank you but it doesn’t work, if you have another idea...

    kglad
    Community Expert
    Community Expert
    May 5, 2020

    show the corrected code you tried