Copy link to clipboard
Copied
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
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();
}
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
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();
}
Copy link to clipboard
Copied
again, // to check for upper left overlap. for centers, adjust.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now