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

Using hitTest in Adobe Animate

Explorer ,
Jan 08, 2020 Jan 08, 2020

Copy link to clipboard

Copied

I used the code from here: https://createjs.com/tutorials/HitTest/ 

This is what I have in the Adobe Animate canvas project:

 

createjs.Ticker.on("tick", tick);

function tick(event) {
	var p = exportRoot.globalToLocal(stage.mouseX, stage.mouseY);
	exportRoot.Pinky.alpha = 0.2;
	if (exportRoot.Pinky.hitTest(p.x, p.y)) { exportRoot.Pinky.alpha = 1; }
	stage.update(event);
}

 

What's happening is that the hitTest is only true when hitting the top left corner of the canvas instead of when hitting the MovieClip from any angle.

TOPICS
Code , How to

Views

1.5K

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
community guidelines

correct answers 1 Correct answer

Explorer , Jan 13, 2020 Jan 13, 2020

This seems to work. I'll need to test it more. I'm not really sure why the hitTest is off by the target's x/y coordinates, though.

if (exportRoot.Pinky.hitTest((p.x-exportRoot.Pinky.x), (p.y-exportRoot.Pinky.y))) { exportRoot.Pinky.alpha = 1; }

Votes

Translate

Translate
Explorer ,
Jan 13, 2020 Jan 13, 2020

Copy link to clipboard

Copied

LATEST

This seems to work. I'll need to test it more. I'm not really sure why the hitTest is off by the target's x/y coordinates, though.

if (exportRoot.Pinky.hitTest((p.x-exportRoot.Pinky.x), (p.y-exportRoot.Pinky.y))) { exportRoot.Pinky.alpha = 1; }

Votes

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
community guidelines