【发布时间】:2014-02-14 17:26:35
【问题描述】:
我正在尝试在 createJS 标签上注册命中测试。
我有两个问题:
1) 如下图所示,只有当我将鼠标悬停在红球上时才会注册命中测试,而不是标签。我认为这是因为球的尺寸要大得多。如何获得标签的命中测试?
2) CreateJS 文档,http://www.createjs.com/tutorials/HitTest/hitTest.html,表明我需要将hitTest 事件放在刻度内。我宁愿不把它放在那里,因为我不希望浏览器一直浪费资源检查 hittest。我可以将hittest 代码放在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);
}
【问题讨论】:
标签: javascript jquery html hittest createjs