Copy link to clipboard
Copied
the rect should be alpha=0.1 once the circle touches the rect . but if statement not working . it becomes 0.1 opacity without hitting
/* js
var circle = new lib.mycircle();
stage.addChild(circle);
var rect = new lib.myrect();
stage.addChild(rect);
rect.x=200;
rect.y=300;
circle.addEventListener('mousedown', downF);
function downF(e) {
stage.addEventListener('stagemousemove', moveF);
stage.addEventListener('stagemouseup', upF);
};
function upF(e) {
stage.removeAllEventListeners();
}
function moveF(e) {
circle.x = stage.mouseX;
circle.y = stage.mouseY;
}
if(circle.hitTest(rect))
{
rect.alpha = 0.1;
}
stage.update();
*/
Don't use hitTest. Use getObjectsUnderPoint
, pass the circle's x/y coordinate, and check if the rectangle is in the returned list.
now its working fine
var p = rect.localToLocal(0, 0, circle);
if (rect.hitTest(p.x, p.y)) {
rect.alpha = 0.1;
} else {
rect.alpha = 1;
}
to download source :
createjs collision localtolocal not hittest .fla | Graphicscoder
Copy link to clipboard
Copied
you're only executing that hittest once, when that code executes.
ie, move the hittest inside moveF
Copy link to clipboard
Copied
moving hittest inside moveF causes a bit better
but same problem .when i start move it goes opacity 0.1 .
i need not to touch rectangle
i have uploaded the file in my server for better understanding
Copy link to clipboard
Copied
easeljs hittest checks a hit between an object and a point. read the docs: EaselJS Tutorial: Using hitTest
Copy link to clipboard
Copied
Don't use hitTest. Use getObjectsUnderPoint
, pass the circle's x/y coordinate, and check if the rectangle is in the returned list.
now its working fine
var p = rect.localToLocal(0, 0, circle);
if (rect.hitTest(p.x, p.y)) {
rect.alpha = 0.1;
} else {
rect.alpha = 1;
}
to download source :
createjs collision localtolocal not hittest .fla | Graphicscoder
Copy link to clipboard
Copied
you're doing what i suggested.
Copy link to clipboard
Copied
you are our teacher . so its normal
you have 205313 points where i have only 10 .
i think 205313 >10
Copy link to clipboard
Copied
that's a good way to not get help in the future, should the need arise. good luck.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now