Skip to main content
Inspiring
March 28, 2016
Answered

flash cc createjs hittest works without hit

  • March 28, 2016
  • 1 reply
  • 2517 views

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();

*/

This topic has been closed for replies.
Correct answer tanvira5454192

easeljs hittest checks a hit between an object and a point.  read the docs: EaselJS Tutorial: Using hitTest


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

1 reply

kglad
Community Expert
Community Expert
March 28, 2016

you're only executing that hittest once, when that code executes.

ie, move the hittest inside moveF

Inspiring
March 28, 2016

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

http://graphicscoder.org/stackover/you/circle.html

kglad
Community Expert
Community Expert
March 28, 2016

easeljs hittest checks a hit between an object and a point.  read the docs: EaselJS Tutorial: Using hitTest