Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ANCC2018,hitTest,How to use

Enthusiast ,
Apr 07, 2018 Apr 07, 2018

createjs.Ticker.addEventListener("tick", pengzhuang);

function pengzhuang() {
var pz=bb.hitTest(aa.x,aa.y);
if(pz==true){alert("yes");}else{alert("no");}
stage.update();
}

Learn how to use HitTest, but fail。

Want to know why

556
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 08, 2018 Apr 08, 2018

use:

createjs.Ticker.addEventListener("tick", pengzhuang.bind(this));

function pengzhuang() {

var pt = this.bb.globalToLocal(this.aa.x,this.aa.y);  // to check for upper left overlap.  for centers, adjust.
if(this.bb.hitTest(pt.x,pt.y)){
console.log('true');

} else {

console.log('false');

}
stage.update();
}

Translate
Community Expert ,
Apr 07, 2018 Apr 07, 2018

bb and aa (and therefore aa.x and aa.y) are probably undefined.  try:

createjs.Ticker.addEventListener("tick", pengzhuang.bind(this));

function pengzhuang() {
if(this.bb.hitTest(this.aa.x,this.aa.y)){
console.log('true');

} else {

console.log('false');

}
stage.update();
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2018 Apr 07, 2018

Thank you,

aa,ande bb is  Movie Clips.

alert("no") is OK

But yes has not been successful,popped up"YES"

var ax=this.a.x

var ay=this.a.y

this.bb.hitTest(ax,ay),No difference

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2018 Apr 07, 2018

444.JPG

555.JPG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2018 Apr 08, 2018

use:

createjs.Ticker.addEventListener("tick", pengzhuang.bind(this));

function pengzhuang() {

var pt = this.bb.globalToLocal(this.aa.x,this.aa.y);  // to check for upper left overlap.  for centers, adjust.
if(this.bb.hitTest(pt.x,pt.y)){
console.log('true');

} else {

console.log('false');

}
stage.update();
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 08, 2018 Apr 08, 2018

Now it's on the left.

What to do if it's a rectangle。

localToLocal,It doesn't work.

createjs. Ticker.addEventListener("tick", pengzhuang.bind(this));


function pengzhuang() {

var ax=this.aa.x
var ay=this.aa.y

var p = this.bb.localToLocal(ax,ay,this.aa);

if (this.bb.hitTest(p.x,p.y)) {
    this.aa.alpha = 0.1;
console.log('yes');
} else {
    this.aa.alpha = 0.9;
console.log('no');
}
stage.update();
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2018 Apr 09, 2018
LATEST

again, // to check for upper left overlap.  for centers, adjust.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines