0
我正試圖在createJS標籤上註冊一個命中測試。createJS標籤測試
我有兩個問題:
1)正如你可以從下面的PIC看到,點擊測試,只有當我將鼠標懸停在紅球,而不是標籤註冊。我認爲這是因爲球的體積更大。我怎樣才能獲得標籤的命中測試?
2)CreateJS文檔http://www.createjs.com/tutorials/HitTest/hitTest.html顯示我需要將hitTest
事件放入tick中。我寧願不把它放在那裏,因爲我不希望瀏覽器一直在浪費資源來檢查命中。我可以把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);
}
1)我想我不完全理解localToGlobal vs globalToLocal vs localToLocal和2)爲什麼我不需要轉換紅球的座標? – Growler
3)hitTest是否需要在tick事件中才能在mousehover上註冊? – Growler