Skip to main content
Inspiring
January 9, 2020
Answered

Using hitTest in Adobe Animate

  • January 9, 2020
  • 1 reply
  • 1988 views

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.

This topic has been closed for replies.
Correct answer RyanS_Extron17202589

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; }

1 reply

RyanS_Extron17202589AuthorCorrect answer
Inspiring
January 14, 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; }