Highlighted

flash cc createjs hittest works without hit

Mar 28, 2016

Copy 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

Topics

ActionScript

Views

1.1K

Likes

Translate

Translate

Report

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

flash cc createjs hittest works without hit

Mar 28, 2016

Copy 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

Topics

ActionScript

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Mar 28, 2016

Copy to clipboard

Copied

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

ie, move the hittest inside moveF

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 28, 2016

Copy 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

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Mar 28, 2016

Copy to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 02, 2016

Copy 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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Apr 02, 2016

Copy to clipboard

Copied

you're doing what i suggested.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 02, 2016

Copy to clipboard

Copied

you are our teacher . so its normal

you have 205313 points where i have only 10 .

i think 205313 >10

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
kglad LATEST
Adobe Community Professional ,
Apr 02, 2016

Copy to clipboard

Copied

that's a good way to not get help in the future, should the need arise.  good luck.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...