Highlighted

Using hitTest in Adobe Animate

Explorer ,
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.

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; }
TOPICS
Code, How to

Views

225

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

Using hitTest in Adobe Animate

Explorer ,
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.

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; }
TOPICS
Code, How to

Views

226

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
Jan 08, 2020 0
Explorer ,
Jan 13, 2020

Copy link to clipboard

Copied

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

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...
Jan 13, 2020 1