[英]How to add events to a matrix drawn with html5?
I just need a development suggestions.I am not that experienced so I do not know all the possibilities I have. 我只需要一个开发建议。我没有那么丰富的经验,所以我不知道我拥有的所有可能性。 So, I try to develop a crossword generator with javascript.
因此,我尝试使用javascript开发填字游戏生成器。 I thought of drawing a matrix on a canvas using HTML5 lines, and because it must be generated I thought of doing this at a press of a button.
我想到了使用HTML5线在画布上绘制矩阵的方法,因为必须生成矩阵,所以我想到了按一下按钮就可以做到这一点。 It would be better with rectangles?
矩形会更好吗? or what other way exists in order to implement the matrix?
还是存在其他方式来实现矩阵? And the most important question of all: how do I add events on the matrix so I can write letters in it?
最重要的问题是:如何在矩阵上添加事件以便可以在其中写字母? All I need is just o suggestion of where to look, for adding events especially.
我所需要的只是建议去哪里看,特别是添加事件。 It is kind of a road block right now so please help if you can.
目前这是一个障碍,因此请您提供帮助。 Thank you.
谢谢。
If I was developing this crossword using canvas, I would use a node structure which holds references to other nodes. 如果使用画布开发此填字游戏,则将使用一个包含对其他节点的引用的节点结构。 for example,
例如,
function node(){
//dims
this.x;
this.y;
this.width;
this.height;
//
this.id;
this.neighbors = [];
...
}
For attaching events to a specific node, you will have to determine the canvas mouse position (e) X, Y position considering the width and height(node), so if the user clicks on a node, you find out the node ID and do something with it. 为了将事件附加到特定节点,您必须考虑宽度和高度(节点)来确定画布鼠标的位置(e)的X,Y位置,因此,如果用户单击某个节点,则需要找出该节点的ID并执行有东西。
For drawing use strokeRect() with fillText() for each node. 对于绘制,对每个节点使用带有fillText()的strokeRect()。
... My A* pathfinding implementation might help you. ...我的A *寻路实施可能会为您提供帮助。 (Graphs, Node structure with canvas) also sorry for messy code or bugs, it was just for fun.
(图形,带画布的Node结构)也为代码混乱或错误感到抱歉,这只是为了好玩。
I hope this helps you. 我希望这可以帮助你。 Happy Holidays.
节日快乐。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.