I'm trying to register a hit test on a createJS label.
I have two questions:
1) As you can see from the pic below, hit test only register when I hover over the red ball, and not the label. I think this is because the ball's size is much larger. How can I get hit test for the label?
2) CreateJS documentation, http://www.createjs.com/tutorials/HitTest/hitTest.html, shows I need to put hitTest
event inside tick. I would rather not put it in there because I don't want the browser to waste resources checking for hittest all the time. Can I put the hittest
code in something like jQuery doc ready
?
stage = new createjs.Stage("demoCanvas");
stage.mouseMoveOutside = true;
circle = stage.addChild(new createjs.Shape());
circle.graphics.beginFill("red").drawCircle(50,50,50);
circle.x = 0;
circle.y = 0;
mylabel = new createjs.Text("testing", "14px Arial", "white");
mylabel.x = 300;
mylabel.y = 100;
stage.addChild(circle, mylabel);
function tick(event) {
if (circle.hitTest(stage.mouseX, stage.mouseY)) {
log("ball hit");
}
if (mylabel.hitTest(stage.mouseX, stage.mouseY)) {
log("label hit");
}
stage.update(event);
}