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

flash cc createjs hittest works without hit

Contributor ,
Mar 28, 2016 Mar 28, 2016

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

*/

TOPICS
ActionScript
2.4K
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

Contributor , Apr 02, 2016 Apr 02, 2016

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

Translate
Community Expert ,
Mar 28, 2016 Mar 28, 2016

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

ie, move the hittest inside moveF

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
Contributor ,
Mar 28, 2016 Mar 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

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 ,
Mar 28, 2016 Mar 28, 2016

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

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
Contributor ,
Apr 02, 2016 Apr 02, 2016

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

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 02, 2016 Apr 02, 2016

you're doing what i suggested.

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
Contributor ,
Apr 02, 2016 Apr 02, 2016

you are our teacher . so its normal

you have 205313 points where i have only 10 .

i think 205313 >10

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 02, 2016 Apr 02, 2016
LATEST

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

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