0
我有2個不同的JavaScript文件。在javascript中訂閱事件
hexagon.js
function HexagonGrid(canvasId, radius) {
this.radius = radius;
this.height = Math.sqrt(3) * radius;
this.width = 2 * radius;
this.side = (3/2) * radius;
this.canvas = document.getElementById(canvasId);
this.context = this.canvas.getContext('2d');
this.canvasOriginX = 0;
this.canvasOriginY = 0;
this.canvas.addEventListener("mousedown", this.clickEvent.bind(this), false);
this.hexGridList = {};
};
HexagonGrid.prototype.clickEvent = function (e) {
var mouseX = e.pageX;
var mouseY = e.pageY;
var localX = mouseX - this.canvasOriginX;
var localY = mouseY - this.canvasOriginY;
**var tile = this.getSelectedTile(localX, localY);**
if (tile.column >= 0 && tile.row >= 0) {
//find
//this.hexGridList['row' + tile.row + 'column' + tile.column].
var drawy = tile.column % 2 == 0 ? (tile.row * this.height) + this.canvasOriginY + 6 : (tile.row * this.height) + this.canvasOriginY + 6 + (this.height/2);
var drawx = (tile.column * this.side) + this.canvasOriginX;
this.drawHex(drawx, drawy - 6, "rgba(110,110,70,0.3)", "");
}
};
Mainpage.js
<script src="Hexagon.js"></script>
var hexagonGrid = new HexagonGrid("HexCanvas", 50);
所以,我的炫魅是運行的頁面,我試圖返回在六邊形的粗體線瓷磚。 js通過鼠標點擊回到mainpage.js。如何在點擊鼠標時從hexagon.js到mainpage.js頁面獲取圖塊對象?
謝謝。完美工作。 – DidIReallyWriteThat