我试图在createJS标签上注册一个命中测试。
我有两个问题:
1)从下面的图片中你可以看到,只有当我悬停在红色球上时,才能注册点击测试,而不是标签。我认为这是因为球的大小要大得多。我怎样才能被标签击中测试呢?
2) CreateJS文档,http://www.createjs.com/tutorials/HitTest/hitTest.html,显示我需要将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);
}

发布于 2014-02-17 09:05:47
https://stackoverflow.com/questions/21785739
复制相似问题